Schoening Posted February 5, 2015 Share Posted February 5, 2015 I am using https://github.com/sole/tween.js/ for tweening. I am making a snake game. For every piece I am creating a tween:function Tween ( array_index ) { var i = array_index; // targets[ i ] this.tween = new TWEEN.Tween( values[ i ] ) .to( targets[ i ] , 500) .onUpdate(function(){ snake[ i ].position.x = this.x; snake[ i ].position.y = this.y; snake[ i ].rotation.z = this.rotation; }) .onComplete(function(){ checkTweenCompletion(); })};But that could look like it is insane when thinking about mobile performance... Can you think of alternatives? Because I can't... Every piece of my snake has to move to the previous piece position. I don't think I can do that in a single tween. Quote Link to comment Share on other sites More sharing options...
alex_h Posted February 5, 2015 Share Posted February 5, 2015 How many simultaneous tweens do you think you are talking about here? Unless there really are a lot of them I don't think it should actually be much of a problem. Have you done tests to check the performance impact? There are a few micro-optimizations you could do though. For example you could reduce impact on the garbage collector by re-using the same tween objects (ie assign one to each snake segment) rather than creating a new one each time you want to move. You could also cache values fetched from arrays in local variables like this.onUpdate(function(){ var s = snake[ i ]; s.position.x = this.x; s.position.y = this.y; s.rotation.z = this.rotation; })but I still wouldn't expect to see a dramatic impact from these kinds of changes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.