Jump to content

Keeping tweens between states


lash
 Share

Recommended Posts

Is there a way to keep tweens running even though you change the state? I've tried in the code below to pass the tween objects with the Phaser.Game.State.start() function, and manually inserting them back into the Phaser.Tweenmanager. Didn't work, although the tween objects themselves are registered as "running" and "not paused"...

 

var game;
var segment_timer;
var outergraphic;

window.onload = function() {
	game = new Phaser.Game(800, 600, Phaser.AUTO, '', {preload: preload, create: create});
	game.state.add("One", stateone);
	
};

var stateone = function(game) {
	this.init = function(t1, t2) {
		this.t1 = t1;
		this.t2 = t2;
	};
};

stateone.prototype = {
	innergraphic: null,
	t1: null,
	t2: null,
	
	init: function() {
	},
	
	create: function() {
		game.tweens.add(this.t1);
		game.tweens.add(this.t2);
		this.t2.resume();
		this.t1.resume();
		this.innergraphic = game.add.graphics(-2000, -2000);
		this.innergraphic.beginFill(0xff0000);
		this.innergraphic.drawRect(0, 0, 50, 50);
		this.innergraphic.endFill();
		this.innergraphic.position.set(50, 50);
		game.world.add(this.innergraphic);
		var t1 = game.tweens.create(this.innergraphic).to({
			x: 600,
			y: 400,
		}, 1000, null, true, 0, 0);
		var t2 = game.tweens.create(this.innergraphic).to({
			x: 50,
			y: 50
		}, 1000, null, false, 0, 0);
		t1.chain(t2);
		t2.chain(t1);
	},
};

function preload() {
	segment_timer  = game.time.create(false);
	
}
function create() {

	outergraphic = game.add.graphics(-2000, -2000);
	outergraphic.beginFill(0x00ff00);
	outergraphic.drawRect(0, 0, 50, 50);
	outergraphic.endFill();
	outergraphic.position.set(50, 400);
	game.world.add(outergraphic);
	var t1 = game.tweens.create(outergraphic).to({
		x: 600,
		y: 50,
	}, 1000, null, true, 0, 0);
	var t2 = game.tweens.create(outergraphic).to({
		x: 50,
		y: 400
	}, 1000, null, false, 0, 0);
	t1.chain(t2);
	t2.chain(t1);	
	segment_timer.add(1500, function() {
		game.state.start("One", false, false, t1, t2);
	}, this);
	segment_timer.start();
}

 

Link to comment
Share on other sites

I wanted to use a separate state for an the cutscene in a cutscene - gameplay - cutscene structured game. In the gameplay section there are randomly generated objects that are falling like feathers, and they should continue falling even though the gameplay ends and cutscene starts.

To me it makes sense to logically structure it like this, but if the engine isn't made for it, then logic isn't much use, I guess.

Anyway I'm curious as to what exactly in the engine is stopping the tweens, and why it's so complicated when for example other displayobjects still can persist?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...