Bomb Sprite Class
An example of extending the Arcade Physics Sprite class to create a custom bomb object with randomized velocity, angular rotation, and world bounds collision.
1024 × 768
import SPRITE_KEYS from "../spriteKeys.js";
export class Bomb extends Phaser.Physics.Arcade.Sprite
{
constructor (scene, x, y)
{
super(scene, x, y, SPRITE_KEYS.FANTASY_TILES, 62);
scene.add.existing(this);
scene.physics.add.existing(this);
this.setSize(18, 18);
this.setBounce(1);
this.setCollideWorldBounds(true);
this.setVelocity(Phaser.Math.Between(-200, 200), 20);
this.setAngularVelocity(Phaser.Math.Between(-10, 10) * 10)
}
}More in GameObjects13 examples
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.Dynamic Texture PlatformsDemonstrates creating custom-sized platform sprites by stamping tile textures onto a Dynamic Texture and configuring them as static Arcade Physics bodies.Floating Score TextDemonstrates a custom BitmapText class that animates upwards and automatically destroys itself using a Tween, creating a classic floating score effect for points.