Rotating a Container
This example shows how rotating a Container automatically rotates all of its child Game Objects, such as images and text, as a single group.
800 × 600
class Example extends Phaser.Scene
{
container;
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('lemming', 'assets/sprites/lemming.png');
}
create ()
{
// Here we've got 1 of each game object:
const image = this.add.image(0, 0, 'lemming');
const text = this.add.text(60, 0, 'Oh No!', { font: '16px Courier', fill: '#00ff00' });
this.container = this.add.container(200, 300, [ image, text ]);
}
update ()
{
this.container.rotation += 0.01;
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#010101',
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);