{"id":138,"date":"2026-06-15T15:20:48","date_gmt":"2026-06-15T06:20:48","guid":{"rendered":"https:\/\/tate.stars.ne.jp\/wpa\/?p=138"},"modified":"2026-06-15T15:20:48","modified_gmt":"2026-06-15T06:20:48","slug":"rexplugin_gamescene","status":"publish","type":"post","link":"https:\/\/tate.stars.ne.jp\/wpa\/rexplugin_gamescene.html","title":{"rendered":"rexplugin_GameScene"},"content":{"rendered":"<pre><code class=\"swift\">\nimport * as Phaser from 'phaser';\nexport class GameScene extends Phaser.Scene {\nprivate joystick: any;\nprivate rexVirtualJoystick: any;\nprivate cursorKeys!: Phaser.Types.Input.Keyboard.CursorKeys;\nprivate player!: Phaser.Physics.Arcade.Sprite;\nprivate yuka?: Phaser.GameObjects.Rectangle;\nprivate timeText!: Phaser.GameObjects.Text;\nprivate joystickArea!: Phaser.Geom.Rectangle;\nprivate enemy2!: Phaser.Physics.Arcade.Sprite & { body: Phaser.Physics.Arcade.Body };\nprivate bullet2!: Phaser.Types.Physics.Arcade.SpriteWithDynamicBody;\nprivate bullets2: any;\nprivate isHit: boolean = false;\nconstructor() {\n  super({ key: 'GameScene' });\n}\n preload() {\n this.load.image('frame1', 'assets\/b01.png');\n this.load.image('frame2', 'assets\/b02.png');\n this.load.image('frame3', 'assets\/b03.png');\n this.load.image('frame4', 'assets\/b04.png');\n this.load.spritesheet('enemy2', 'assets\/enemy2.png',\n  {frameWidth: 32, frameHeight: 32});\n this.load.image(\"bullet2\", \"assets\/laser.png\");\n this.load.image('frame5', 'assets\/b05.png');\n this.load.image('frame6', 'assets\/b06.png');\n this.load.image('frame7', 'assets\/b07.png');\n this.load.image('frame8', 'assets\/b08.png');\n }\n create() {\n  const textStyle = {\n    fontFamily: 'Arial',\n    fontSize: '25px',\n     fill: '#333333'\n };\n this.timeText = this.add.text(20, 20, '', textStyle);\n this.timeText.setScrollFactor(0);\n this.time.addEvent({\n  delay: 1000,\n   loop: true,\n   callback: () => {\n   const now = new Date();\n   const year = now.getFullYear();\n   const month = now.getMonth() + 1;\n   const date = now.getDate();\n   const hours = String(now.getHours()).padStart(2, '0');\n   const minutes = String(now.getMinutes()).padStart(2, '0');\n const seconds = String(now.getSeconds()).padStart(2, '0');\n  this.timeText.setText(`${year}\/${month}\/${date} ${hours}:${minutes}:${seconds}`);\n }\n});\nthis.anims.create({\nkey: \"left2\", frameRate: 2, repeat: -1,\nframes: this.anims.generateFrameNumbers('enemy2', {start: 4, end: 5}),\n});\nthis.anims.create({\nkey: \"right2\", frameRate: 2, repeat: -1,\nframes: this.anims.generateFrameNumbers('enemy2', {start: 6, end: 7}),\n });\nthis.enemy2 = this.physics.add.sprite(400, 300, 'enemy2').setScale(1.9);\nthis.enemy2.setCollideWorldBounds(true).setDepth(4);\nthis.anims.create({\n key: 'walk',\n  frames: [\n   { key: 'frame1' },\n   { key: 'frame2' },\n   { key: 'frame3' },\n   { key: 'frame4' }\n],\n  frameRate: 10, \/\/ 1\u79d2\u9593\u306b\u5207\u308a\u66ff\u308f\u308b\u30d5\u30ec\u30fc\u30e0\u6570\n   repeat: -1     \/\/ -1\u306f\u7121\u9650\u30eb\u30fc\u30d7\n });\nthis.anims.create({\n   key: 'die',\n  frames: [\n   { key: 'frame5' },\n   { key: 'frame6' },\n   { key: 'frame7' },\n   { key: 'frame8' }\n ],\nframeRate: 4, \/\/ 1\u79d2\u9593\u306b\u5207\u308a\u66ff\u308f\u308b\u30d5\u30ec\u30fc\u30e0\u6570\n repeat: 0,\n });\n\nthis.anims.create({\n key: \"stop\",\n  frames: [{key: 'frame1', frame: 1}],\nframeRate: 10\n});\nthis.bullet2 = this.physics.add.sprite(-20, -20, \"bullet2\");\nthis.bullets2 = this.physics.add.group({\n defaultKey: 'bullet2',\nmaxSize: 70,\nrunChildUpdate: true\n});\nthis.time.addEvent({\ndelay: 2200,\n callback: this.fireBullet,\ncallbackScope: this,\n loop: true\n});\nthis.player = this.physics.add.sprite(  150, 250, 'frame1');\nthis.player.setScale(0.6);\nthis.player.setFlipX(true);\n \/\/ --- A: \u5358\u8272\u3067\u5857\u308a\u3064\u3076\u3059\u5834\u5408 ---\n this.player.setTint(0x000080).setTintMode(Phaser.TintModes.FILL);\nthis.player.setCollideWorldBounds(true);\nthis.yuka = this.add.rectangle(0, 350, 950, 200, 0x00FFFF).setOrigin(0);\nthis.physics.add.existing(this.yuka, true);\nthis.physics.add.existing(this.player);\nthis.physics.add.collider(this.player, this.yuka);\nthis.physics.add.collider(this.enemy2, this.yuka);\nthis.joystickArea = new Phaser.Geom.Rectangle(0, 0, 770, 550);\n\/\/ \u30c7\u30d0\u30c3\u30b0\u7528\u306b\u30a8\u30ea\u30a2\u3092\u8868\u793a\uff08\u52d5\u4f5c\u78ba\u8a8d\u5f8c\u524a\u9664\u3057\u3066\u304f\u3060\u3055\u3044\uff09\nconst graphics = this.add.graphics();\ngraphics.lineStyle(2, 0x00ff00);\ngraphics.strokeRectShape(this.joystickArea);\n\/\/ 1. \u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u306e\u4f5c\u6210\nthis.joystick = (this.plugins.get('rexVirtualJoystick') as any).add(this, {\n x: 100,\n y: 400,\n  radius: 100,\n base: this.add.circle(0, 0, 100, 0x0000FF).setAlpha(0.1),\nthumb: this.add.circle(0, 0, 50, 0xFFA500).setAlpha(0.5),\ndir: '8dir',   \/\/ 8\u65b9\u5411\u5165\u529b\nforceMin: 16,\n fixed: false,  \/\/ \u3053\u3053\u3092false\u306b\u8a2d\u5b9a\nenable: true\n}).setVisible(false); \/\/ \u6700\u521d\u306f\u975e\u8868\u793a\u306b\u3057\u3066\u304a\u304f\nthis.input.on('pointerdown', (pointer: Phaser.Input.Pointer) => {\nif (this.joystickArea.contains(pointer.x, pointer.y)) {\n\/\/ 4. \u30b8\u30e7\u30a4\u30b9\u30c6\u30a3\u30c3\u30af\u3092\u305d\u306e\u4f4d\u7f6e\u306b\u79fb\u52d5\u3057\u3066\u8868\u793a\nthis.joystick.setPosition(pointer.x, pointer.y);\nthis.joystick.setVisible(true);\nthis.joystick.base.depth = 100; \/\/ \u5fc5\u8981\u306b\u5fdc\u3058\u3066\u91cd\u306a\u308a\u9806\u3092\u8abf\u6574\nthis.joystick.thumb.depth = 101;\n }\n });\n\/*\nthis.input.on('pointerdown', (pointer: Phaser.Input.Pointer) => {\nthis.joystick.x = pointer.x;\nthis.joystick.y = pointer.y;\nthis.joystick.setVisible(true); \/\/ \u30bf\u30c3\u30c1\u3057\u305f\u5834\u6240\u3067\u8868\u793a\nthis.joystick.base.depth = 100; \/\/ \u5fc5\u8981\u306b\u5fdc\u3058\u3066\u91cd\u306a\u308a\u9806\u3092\u8abf\u6574\nthis.joystick.thumb.depth = 101;\n });\n *\/\n\/\/ \u6307\u3092\u96e2\u3057\u305f\u6642\u306b\u975e\u8868\u793a\u306b\u3059\u308b\u5834\u5408\nthis.input.on('pointerup', () => {\n  this.joystick.setVisible(false);\n });\nthis.physics.add.overlap(this.player, this.bullets2, this.handleHit, undefined, this);\n }\n private handleHit(playerObj: any, bulletObj: any) {\nif (this.isHit) return;\nconst player = playerObj as Phaser.Physics.Arcade.Sprite;\nconst bullet = bulletObj as Phaser.Physics.Arcade.Image;\nbullet.destroy();\n  this.isHit = true;\n  player.setVelocity(0, 0);\n  player.play('die');\n  this.time.delayedCall(1000, () => {\n  this.isHit = false;\n    player.play('stop');\n  }, [], this);\n }\n\nfireBullet() {\n let bullet2 = this.bullets2.get(this.enemy2.x, this.enemy2.y+10);\nif (bullet2) {\n  bullet2.body.allowGravity = false;\nbullet2.enableBody = true;\n \/\/    bullet2.visible = false;\n bullet2.setScale(0.5);\n  if (this.enemy2.flipX) {\n   bullet2.body.velocity.x = 300;\n } else {\n    bullet2.body.velocity.x = -300;\n   }\n  }\n }\nupdate() {\n if (this.isHit) {\n  this.player.setVelocity(0, 0);\n   return;\n }\n this.enemy2.anims.play('left2', true);\n  if (this.enemy2.x >= 750) {\n    this.enemy2.anims.play('left2', true);\n   this.enemy2.flipX = false;\n     this.enemy2.setVelocityX(-100);\n } else if (this.enemy2.x <= 500) {\nthis.enemy2.flipX = true;\n  this.enemy2.setVelocityX(100);\n }\n const cursorKeys = this.joystick.createCursorKeys();\n if (cursorKeys.left.isDown) {\n this.player.setVelocityX(-200);\n this.player.flipX = false;\n this.player.anims.play('walk', true);\n } else if (cursorKeys.right.isDown) {\n  this.player.setVelocityX(200);\n this.player.flipX = true;\n this.player.anims.play('walk', true);\n } else {\n this.player.setVelocityX(0);\n  this.player.anims.play(\"stop\", true);\n }\nif (cursorKeys.up.isDown) {\nthis.player.setVelocityY(-200);\nif (this.player.y < 100) {\nthis.player.setVelocityY(0);\n }\n }\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-138","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\/138","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=138"}],"version-history":[{"count":1,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":139,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts\/138\/revisions\/139"}],"wp:attachment":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/media?parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/categories?post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/tags?post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}