3ddy

Something messing timings in game

Recommended Posts

Hello, I have a larger project using P2 physics with many tweens and the game sometimes moves randomly, some objects have some delays etc, even when game runs on almost stable 60fps. I've made a simple example in Phaser 2.4.6:

 

var level = 1;

intro = function(game) {};

intro.prototype = {

	create: function() {
		this.stage.backgroundColor = "#ffffff";
		game.time.events.add(2000, this.spawnWater, this, 4);
	},

	spawnWater: function(amount) {
		for (var i = 0; i < amount; i++) {
            var topwater = game.add.sprite(683, 150, 'graphics2', 'static/smth/line.png');
			topwater.anchor.setTo(0.5);
			topwater.scale.setTo(0.2);
			topwater.scaleTween = game.add.tween(topwater.scale).to({x: 1, y: 1}, 2000, Phaser.Easing.Cubic.In, true, (i*500), -1, false);
			topwater.positionTween = game.add.tween(topwater.position).to({y: 670}, 2000, Phaser.Easing.Cubic.In, true, (i*500), -1, false);	
        }
	},
};

What should it do :
- after 2 seconds it should spawn 4 lines
- each line has 2 tweens, for scale and position.
- tweens starts after 0, 500, 1000 and 1500 ms and they are looped infinitely (so they start again from starting values.
- there should be line moving from y = 150 to y = 670 every 500 ms

How does it work:
When reloading the game sometimes the lines are moving correctly (that means every 500ms there is a line), but sometimes after first 4 lines there is longer gap (longer than 500ms) and is messing the way the lines are moving.... What is wrong?

EDIT: 
delay times in tweens were wrong, fixed it from (i+1)*500 to (i*500)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.