Jump to content

Shaking Units with Tweens


InsOp
 Share

Recommended Posts

Hey, 

I have a 2d field with units occupiing several fields. I change position of this units once in a while - but the data for the positions

comes from a node server.

 

that being said: i have some "airunits" and I wanted to implement a certain shaking - to create an illusion of them floating.

So I added this code

game.phaser.add.tween(unit.sprite)       .to({x:unit.sprite.position.x+1,y:unit.sprite.position.y-1},         400, Phaser.Easing.Bounce.InOut, true, 0, -1, true);

works like a charm except for some critical aspects:

  • I cannot move my unit around, now since the tweening interferes with my manual sprite positioning
  • I wouldve liked it more randomized, so my aircraft does float more casual

I could have implemented this aspect by myself somehow, but I like the smooth easing.

Is there a good approach for this issue? Is the issue sufficient described?

Link to comment
Share on other sites

Hi, few suggestions for you.

1. Add your unit.sprite to a Phaser.Group. Then you can shake tween unit.sprite and move the unit around yourself by moving the group.

2. Instead of setting your tween to repeat forever, just tween it once and use the onComplete signal to tween it again with random values.

Also using separate tweens for the x and y values with different durations will create a more random feel.

Link to comment
Share on other sites

Hi, you can make custom easing function with parameters that will move or shake your airunit forever. I wrote 3 part tutorial on making simple game and in part 2 there is "wiggle" function for dron (http://sbcgamesdev.blogspot.cz/2015/05/phaser-tutorial-dronshooter-simple-game_9.html)

 

Here is also tutorial for creating custom easing functions that can take parameters other than "k": http://sbcgamesdev.blogspot.cz/2015/04/phaser-tutorial-custom-easing-functions.html

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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