Sign in to follow this  
InsOp

Shaking Units with Tweens

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?

Share this post


Link to post
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.

Share this post


Link to post
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

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.