geleto Posted December 6, 2017 Share Posted December 6, 2017 I could probably mess with currentTransform from update(), but is there a better way to tween a sprite rotation? Quote Link to comment Share on other sites More sharing options...
geleto Posted December 6, 2017 Author Share Posted December 6, 2017 ... I've found a solution: game.RotatableEntity = me.Entity.extend({ init: function(x, y, sprite) { this._super(me.Entity, "init", [x, y, { width: sprite.width, height: sprite.height }]); this.renderable = sprite; this.currentAngle = 0; this.prevAngle = 0; }, update: function() { this.renderable.currentTransform.rotate(this.currentAngle-this.prevAngle); this.prevAngle = this.currentAngle; return true; } }); Quote Link to comment Share on other sites More sharing options...
obiot Posted December 7, 2017 Share Posted December 7, 2017 that's exactly what I do as well in one of my project, but in my case I pass an increment delta angle so that the object keep spinning (I just need then to negate the value if I want to reverse the rotation) If you want to tween it, then you can either change the delta angle value passed to rotate, or change the target angle in your case. Quote Link to comment Share on other sites More sharing options...
Parasyte Posted December 7, 2017 Share Posted December 7, 2017 The me.Tween class provides a callback that is called with a delta on each frame. The delta can be passed directly to the rotate method; no need to manage state on the class at all. Quote Link to comment Share on other sites More sharing options...
obiot Posted December 7, 2017 Share Posted December 7, 2017 indeed, I never think to use that one to be honest.... and admittedly, the documentation is not super clear as well about it : http://melonjs.github.io/melonJS/docs/me.Tween.html#onUpdate Quote Link to comment Share on other sites More sharing options...
Parasyte Posted December 7, 2017 Share Posted December 7, 2017 I used it in Neverwell Moor for the intro scrolling: https://github.com/blipjoy/nm-prototype/blob/gh-pages/js/objects/screens.js#L357-L384 Quote Link to comment Share on other sites More sharing options...
geleto Posted December 7, 2017 Author Share Posted December 7, 2017 I don't get the delta in the callback. It seems to pass the current tween value in the 0-1 range except that for InOut easing, when reaching 1, instead of tweening back to 0 - it starts incrementing from 0. Here's a fiddle: https://jsfiddle.net/o8dpLngw/1/ ...onUpdate( function(val){ console.log( logo.currentAngle, val*maxAngle, (1-val)*maxAngle) } )... 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.