Align In Top Center
Demonstrates how to align one Game Object to the inner top-center position of another Game Object using the Display Align utility.
800 × 600
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('pic', 'assets/pics/barbarian-loading.png');
this.load.image('block', 'assets/sprites/block.png');
}
create ()
{
const pic = this.add.image(0, 0, 'pic');
const block = this.add.image(0, 0, 'block');
// Center the picture in the game
Phaser.Display.Align.In.Center(pic, this.add.zone(400, 300, 800, 600));
// Center the sprite to the picture
Phaser.Display.Align.In.TopCenter(block, pic);
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.WEBGL,
parent: 'game-container',
width: 800,
height: 600,
scene: Example
};
const game = new Phaser.Game(config);