Jump to content

What is tweening?


Uibon
 Share

Recommended Posts

Personally I am very new to game development and have recently picked up phaser. I have seen a lot of phaser games use tweening. I do not understand what it means. The examples on the website do not clear it up either. Can anyone explain to me what tweening is and how it related to phaser?

Link to comment
Share on other sites

Tween is an animation term.

You define a pair of keyframes: beginning and end, and the computer will compute the in-beTWEEN frames.

Wiki-link!

 

In Phaser, you create Tween objects that will handle changing values from what they currently are, to what you want them to be.

Examples are a sprites position, rotation, scale, alpha.

Usually the transition of values is linear, but Phaser has some other built in options for different effects.

Link to comment
Share on other sites

i do this but it does not work..? any Ideas?

  if (side === 0) {    enemy.reset(wh/2,0);    game.add.tween(enemy).to( {y: wh}, 3000, Phaser.Easing.Linear.None).start();  } else if (side === 1) {    enemy.reset(wh,wh/2);    game.add.tween(enemy).to( {x: 0}, 3000, Phaser.Easing.Linear.None).start();  } else if (side === 2) {    enemy.reset(wh/2,wh);    game.add.tween(enemy).to({y: 0 }, 3000, Phaser.Easing.Linear.None).start();  } else if (side === 3) {    enemy.reset(0,wh/2);    game.add.tween(enemy).to( {x: wh}, 3000, Phaser.Easing.Linear.None).start();  }

side is a randomly generated number to indicate starting side while wh stores the game dimensions(300, 300)

Link to comment
Share on other sites

No, wh is a number, yet it still does not work. 

I use this in my create function and it works 

  testEnemy = game.add.sprite(0,0,'e1');  game.add.tween(testEnemy).to({x: 300,y: 300}, 2000).start();

But  does not work when I use it like this:

if(rand_int(2) === 0) {  enemy = enemies1.getFirstExists(false);} else {  enemy = enemies2.getFirstExists(false);}enemy.reset(wh/2,0);enemy.x = wh/2;game.add.tween(enemy).to({x: 300,y: 300}, 2000, null, true);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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