Change Texture Frame
Demonstrates how to change a Game Object's texture frame as part of a tween, combined with other property changes like position and scale.
800 × 600
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.atlas('assets', 'assets/atlas/tweenparts.png', 'assets/atlas/tweenparts.json');
}
create ()
{
const chest = this.add.image(400, 600, 'assets', 'blue-open').setOrigin(0.5, 1);
// After 2 seconds the frame will change to 'blue-open'
this.tweens.add({
targets: chest,
texture: [ 'assets', 'blue-closed' ],
duration: 500,
repeat: -1,
yoyo: true,
y: chest.y - 50,
scaleY: 1.2,
ease: 'Back.out'
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#2d2d2d',
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);