Jump to content

How expensive are tweens? Are there alternatives?


Jonchun
 Share

Recommended Posts

Hello,

 

I'm working on a multiplayer game, and I need to do the following:

 

Enemy X, Y coordinates are updated roughly ~100ms

 

I have a sprite representing the enemy. I can update x,y directly, but that would result in choppy movement. What would be the best way to have the sprite move from coordinate x1, y1 to x2,y2 in small, smooth increments given that x2 and y2 might be updated at any time?

Link to comment
Share on other sites

Well, I made this little demo to show that you can achieve a good speed with tweens, at least on a decent PC. I make the program do a tween every update, and then change the values. Replace the changing of values int the update function with getting the values from the game server, and you will be able to render it. The main concern for speed here isn't the hardware, but the connection, because the FPS will be limited to what the network can offer. Have Fun!

var game = new Phaser.Game(640, 480, Phaser.AUTO, '', { preload: preload, create: create, update: update });var xsprite = 0;var ysprite = 0;function preload(){game.load.image('spr', 'assets/spr.png');}function create(){sprite = game.add.sprite(x, y, 'spr');}function update(){xsprite=x+1;ysprite=y+1;tween = game.add.tween(sprite).to({ x:xsprite, y: ysprite }, 1, Phaser.Easing.Linear.None, true);}
Link to comment
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...
 Share

  • Recently Browsing   0 members

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