Jump to content

Tween not working


gurubw
 Share

Recommended Posts

Somehow I can't get Tween to work. The rest of the code is working fine, but when using a Tween nothing happens. onStart and onComplete are not being called and there are no errors in console. Suggestions?

var bottom = new game.Sprite('blacktile.png');        bottom.anchor.set(0, 1);        bottom.position.set(0, game.system.height - 20);        bottom.width = game.system.width / 1.5;        this.stage.addChild(bottom);        var tween = new game.Tween(bottom.position);        tween.to({x:200},1000);        tween.start();        this.textlabel = new PIXI.Text("Moves: " + this.moves, {font:"50px Arial", fill:"black"});		this.stage.addChild(this.textlabel);        		for(var i = 0; i <= this.board.getcolumncount(); i++)		{									var vert = new game.Sprite('blacktile.png');			vert.anchor.set(0,1);			this.columnspace = (bottom.width - ((this.board.getcolumncount() + 1) * this.blockwidth)) / this.board.getcolumncount();						vert.position.set(i*this.blockwidth + i*this.columnspace, bottom.position.y - this.blockwidth);						vert.height = this.columnspace*3+10;			this.stage.addChild(vert);			this.vertcolumns[this.vertcolumns.length] = vert;		}		this.board.initblocks(this.columnspace, this.blockwidth, bottom.position.y - this.blockwidth);			var columns = this.board.getcolumns();		for(var i = 0; i < columns.length; i++)		{			for(var x = 0; x < columns[i].length; x++)			{				this.stage.addChild(columns[i][x].getsprite());                this.stage.addChild(columns[i][x].getlabel());			}		}
Link to comment
Share on other sites

Ok, changed it with onComplete and onStart and added the full scene code. Thnx for looking at it. So far, i'm pretty impressed by your panda.js project, works like a charm!

SceneGame = game.Scene.extend({    backgroundColor: 0xb9bec7,    board: new Board(4),    moves: 0,    textlabel: null,    blockwidth: 32,    columnspace: 0,    clickA: 0,    clickB: 0,    clickcount: 0,    vertcolumns: new Array(),        init: function() {    	        var bottom = new game.Sprite('blacktile.png');        bottom.anchor.set(0, 1);        bottom.position.set(0, game.system.height - 20);        bottom.width = game.system.width / 1.5;        this.stage.addChild(bottom);        var tween = new game.Tween(bottom.position);        tween.to({x:200},1000);        tween.onStart(function(){console.log('Tween started')});        tween.onComplete(function(){console.log('Tween completed')});        tween.start();        this.textlabel = new PIXI.Text("Moves: " + this.moves, {font:"50px Arial", fill:"black"});		this.stage.addChild(this.textlabel);        		for(var i = 0; i <= this.board.getcolumncount(); i++)		{									var vert = new game.Sprite('blacktile.png');			vert.anchor.set(0,1);			this.columnspace = (bottom.width - ((this.board.getcolumncount() + 1) * this.blockwidth)) / this.board.getcolumncount();						vert.position.set(i*this.blockwidth + i*this.columnspace, bottom.position.y - this.blockwidth);						vert.height = this.columnspace*3+10;			this.stage.addChild(vert);			this.vertcolumns[this.vertcolumns.length] = vert;		}		this.board.initblocks(this.columnspace, this.blockwidth, bottom.position.y - this.blockwidth);			var columns = this.board.getcolumns();		for(var i = 0; i < columns.length; i++)		{			for(var x = 0; x < columns[i].length; x++)			{				this.stage.addChild(columns[i][x].getsprite());                this.stage.addChild(columns[i][x].getlabel());			}		}    },        click: function(event)    {    	    	for(var i = 0; i < this.vertcolumns.length; i++)    	{    		var xStart = this.vertcolumns[i].position.x + this.blockwidth;    		var yStart = this.vertcolumns[i].position.y - this.vertcolumns[i].height;    		var xEnd = this.vertcolumns[i].position.x + this.blockwidth + this.columnspace;    		var yEnd = this.vertcolumns[i].position.y;    		if ((event.global.x > xStart) & (event.global.x < xEnd) & (event.global.y > yStart) & (event.global.y < yEnd))    		{    			if (this.clickcount == 0)    			{    				this.clickA = i;    				this.clickcount++;    				console.log("A:" + i);    			}    			else if (this.clickcount == 1)    			{    				this.clickB = i;    				console.log("B:" + i);    				if (this.board.moveblock(this.clickA, this.clickB))    					this.moves++;    				this.clickcount = 0;    			}    			console.log("count:" + this.clickcount);    		}    	}            	    },        update:function()    {    	    	this.textlabel.setText("Moves: " + this.moves);    	var columns = this.board.getcolumns();		for(var i = 0; i < columns.length; i++)		{			for(var x = 0; x < columns[i].length; x++)			{				columns[i][x].getsprite();                columns[i][x].getlabel();			}		}    	    	    }});
Link to comment
Share on other sites

  • 2 weeks later...

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...
 Share

  • Recently Browsing   0 members

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