Treasure Box Game Object
A custom Arcade Physics Sprite class representing a treasure box that changes its animation frame and triggers a key spawn when activated.
1024 × 768
import SPRITE_KEYS from "../spriteKeys.js";
export class TreasureBox extends Phaser.Physics.Arcade.Sprite
{
isActivated = false;
constructor (scene, x, y)
{
super(scene, x, y, SPRITE_KEYS.FANTASY_TILES, 49);
this.setOrigin(0, 0);
scene.add.existing(this);
scene.physics.add.existing(this, true);
}
activate()
{
if (this.isActivated) return;
this.isActivated = true;
this.setFrame(50);
this.scene.addKey(this.x + (this.width*0.5), this.y + (this.height*0.5));
}
}More in GameObjects13 examples
Animated Coin Collection EffectDemonstrates a custom Sprite class that manages its own spin animation, yoyo tween movement, sound effects, and self-destruction upon completion.Automated Sprite AI (Chick)A custom Arcade Physics Sprite class demonstrating automated movement, jumping on a timer, and collision-based direction switching.Bomb Sprite ClassAn example of extending the Arcade Physics Sprite class to create a custom bomb object with randomized velocity, angular rotation, and world bounds collision.Collectible Physics SpriteDemonstrates creating a custom Sprite class with Arcade Physics, featuring randomized bounce properties, collection logic, and physics body resetting.