{"id":151,"date":"2026-07-15T14:43:13","date_gmt":"2026-07-15T05:43:13","guid":{"rendered":"https:\/\/tate.stars.ne.jp\/wpa\/?p=151"},"modified":"2026-07-15T14:43:14","modified_gmt":"2026-07-15T05:43:14","slug":"myplayer2scoretext","status":"publish","type":"post","link":"https:\/\/tate.stars.ne.jp\/wpa\/myplayer2scoretext.html","title":{"rendered":"myPlayer2ScoreText"},"content":{"rendered":"<pre><code class=\"swift\">\nimport * as Phaser from 'phaser';\nexport class ScoreText extends Phaser.GameObjects.Text {\nconstructor(scene: Phaser.Scene, x: number, y: number) {\n \/\/ \u521d\u671f\u5316\u6642\u306b\u30ec\u30b8\u30b9\u30c8\u30ea\u304b\u3089 'score' \u306e\u5024\u3092\u53d6\u5f97\uff08\u306a\u3051\u308c\u30700\uff09\nconst currentScore = scene.registry.get('score') || 0;\n super(scene, x, y, `Score: ${currentScore}`, {\n fontSize: '32px',\ncolor: '#ffffff'\n});\n\/\/ \u30b7\u30fc\u30f3\u306b\u3053\u306e\u30c6\u30ad\u30b9\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8ffd\u52a0\nscene.add.existing(this);\n\/\/ registry\u306e'score'\u30c7\u30fc\u30bf\u304c\u5909\u66f4\u3055\u308c\u305f\u3089\u8868\u793a\u3092\u66f4\u65b0\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u3092\u767b\u9332\nscene.registry.events.on('changedata-score', this.updateScore, this);\n\/\/ \u30b7\u30fc\u30f3\u304c\u7834\u68c4\u30fb\u30b7\u30e3\u30c3\u30c8\u30c0\u30a6\u30f3\u3055\u308c\u308b\u6642\u306b\u30a4\u30d9\u30f3\u30c8\u3092\u89e3\u9664\uff08\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u9632\u6b62\uff09\nscene.events.on('shutdown', () => {\nscene.registry.events.off('changedata-score', this.updateScore, this);\n});\n}\nprivate updateScore(parent: any, value: number): void {\nthis.setText(`Score: ${value}`);\n}\n \/\/ \u30b9\u30b3\u30a2\u3092\u52a0\u7b97\u3059\u308b\u305f\u3081\u306e\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\npublic addScore(amount: number): void {\nconst currentScore = this.scene.registry.get('score') || 0;\nthis.scene.registry.set('score', currentScore + amount);\n }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import * as Phaser from &#8216;phase&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-phaser4","category-typescript"],"_links":{"self":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":1,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":152,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts\/151\/revisions\/152"}],"wp:attachment":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}