Relative Value Tweens
Demonstrates how to use string operators like += and -= to create tweens relative to an object's current property values.
800 × 600
class Example extends Phaser.Scene
{
constructor()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('block', 'assets/sprites/block.png');
}
create ()
{
var image = this.add.image(100, 100, 'block');
var tween = this.tweens.add({
targets: image,
props: {
x: { value: '+=500', duration: 3000, ease: 'Power2' },
y: { value: '+=300', duration: 1500, ease: 'Bounce.easeOut' }
},
delay: 1000
});
console.log(tween);
}
}
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);