Build games as easily as you play them — join the Phaser Beam waitlist for Early Access.
class Example extends Phaser.Scene { preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v385'); this.load.image('block', 'assets/sprites/block.png'); this.load.image('flower', 'assets/sprites/flower-exo.png'); } create () { const block = this.physics.add.image(400, 100, 'block') .setVelocity(100, 200) .setBounce(1, 1) .setCollideWorldBounds(true); const flower = this.add.image(0, 0, 'flower'); this.events.on('postupdate', () => { Phaser.Display.Align.To.TopCenter(flower, block); }); } } const config = { type: Phaser.AUTO, width: 800, height: 600, parent: 'phaser-example', physics: { default: 'arcade', arcade: { debug: true } }, scene: Example }; const game = new Phaser.Game(config);
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v385');
this.load.image('block', 'assets/sprites/block.png');
this.load.image('flower', 'assets/sprites/flower-exo.png');
}
create ()
{
const block = this.physics.add.image(400, 100, 'block')
.setVelocity(100, 200)
.setBounce(1, 1)
.setCollideWorldBounds(true);
const flower = this.add.image(0, 0, 'flower');
this.events.on('postupdate', () =>
{
Phaser.Display.Align.To.TopCenter(flower, block);
});
}
}
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'phaser-example',
physics: {
default: 'arcade',
arcade: { debug: true }
},
scene: Example
};
const game = new Phaser.Game(config);