class Example extends Phaser.Scene {
preload() {
// Assets : https://kenney.nl/
this.load.image("duck", "https://assets.codepen.io/9367036/duck.png");
}
create() {
const img = this.add.image(136, 136, "duck");
img.x = 100;
img.y = 200;
let timeline = this.add.timeline();
timeline.add({
at: 0,
tween: {
targets: img,
x: 400,
angle: -90,
ease: "Expo.easeOut",
duration: 1500
}
});
timeline.add({
at: 0,
tween: {
targets: img,
y: 100,
ease: "Sine.easeIn",
duration: 1500
}
});
timeline.add({
at: 1500,
tween: {
targets: img,
y: 300,
ease: "Sine.easeInOut",
duration: 500
}
});
timeline.add({
at: 2000,
tween: {
targets: img,
x: 700,
y: 200,
angle: 0,
ease: "Expo.easeIn",
duration: 1000
}
});
timeline.add({
at: 2000,
tween: {
targets: img,
y: 200,
ease: "Sine.easeOut",
duration: 1000
}
});
timeline.add({
at: 3000,
tween: {
targets: img,
x: 100,
y: 200,
angle: 360,
duration: 1000
}
});
// Tween de cloture pour la répétition
timeline.add({
at: 4000,
tween: {
targets: img
}
});
timeline.play().repeat();
}
}
const config = {
type: Phaser.AUTO,
transparent: true,
width: 800,
height: 400,
scene: Example
};
const game = new Phaser.Game(config);