Phaser tween lag
Tweens made of multiple TweenData lag behind single-TweenData tweens of the same total duration
HTML
<script src="https://rawgit.com/photonstorm/phaser-ce/master/build/phaser.min.js"></script>
<div id="game_div"> </div>
CSS
#game_div {
width: 400px;
margin: auto;
margin-top: 50px;
}
JavaScript
// Initialize Phaser, and creates a 400x490px game
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');
var game_state = {};
// Creates a new 'main' state that wil contain the game
game_state.main = function() { };
game_state.main.prototype = {
preload: function() {
game.load.baseURL = 'http://examples.phaser.io/assets/';
game.load.crossOrigin = 'anonymous';
game.load.image('phaser', 'sprites/phaser-dude.png');
},
create: function() {
window.game = this;
//Create two identical sprites
window.sprite1 = game.add.sprite(0, 0, 'phaser');
window.sprite2 = game.add.sprite(0, 0, 'phaser');
//running it frame-based makes it worse...
//game.tweens.frameBased = true;
//Tween 1 has 1 TweenData
window.twn1 = game.add.tween(sprite1);
twn1.to({
x: 250
}, 1000).loop();
//Tween 2 has 10 TweenData covering the same distance in the same time
window.twn2 = game.add.tween(sprite2);
twn2.to({
x: 25
}, 100).to({
x: 50
}, 100).to({
x: 75
}, 100).to({
x: 100
}, 100).to({
x: 125
}, 100).to({
x: 150
}, 100).to({
x: 175
}, 100).to({
x: 200
}, 100).to({
x: 225
}, 100).to({
x: 250
}, 100).loop();
twn1.start();
twn2.start();
},
update: function() {
},
};
// Add and start the 'main' state to start the game
game.state.add('main', game_state.main);
game.state.start('main');