Animated Coin Collection Effect
Demonstrates a custom Sprite class that manages its own spin animation, yoyo tween movement, sound effects, and self-destruction upon completion.
1024 × 768
import ANIMATION_KEYS from "../animationKeys.js";
import AUDIO_KEYS from "../audioKeys.js";
import SPRITE_KEYS from "../spriteKeys.js";
export class Coin extends Phaser.GameObjects.Sprite
{
moveY = 96;
gameUiScene;
constructor (scene, x, y)
{
super(scene, x, y, SPRITE_KEYS.FANTASY_TILES, 52);
scene.add.existing(this);
scene.tweens.add({
targets: this,
y: y - this.moveY,
duration: 300,
ease: 'Quad.easeOut',
yoyo: true,
onComplete: () => {
this.destroy();
scene.addScore(this.x, this.y, 100);
}
});
this.play(ANIMATION_KEYS.COIN_SPIN);
this.gameUiScene = scene.scene.get('GameUi');
this.gameUiScene.playAudio(AUDIO_KEYS.COIN);
}
}More in GameObjects13 examples
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.Custom Player Sprite ClassAn example of encapsulating player logic, such as movement, animations, and jumping, within a class that extends the Arcade Physics Sprite.