bali33 Posted October 2, 2014 Share Posted October 2, 2014 Hi guys, I was wondering if there is a way to call a function once per frame inside a Class that inherit from Sprite for example ? I'm asking that because I'm trying to do something very simple but don't know how to achieve this. I want to be able to drag an object and when the mouse is released let the object keep moving according to its current velocity until it reached 0. So my first thought has been to look a way to call a function every frame in order to move the object, decrease the speed, check the speed value and if 0 stop calling this function. Is that possible and the right way to do ? Thank you Quote Link to comment Share on other sites More sharing options...
xerver Posted October 2, 2014 Share Posted October 2, 2014 Override updateTransform which is called each frame for DisplayObjects. Make sure to call the parent function as well when you override it. Quote Link to comment Share on other sites More sharing options...
bali33 Posted October 2, 2014 Author Share Posted October 2, 2014 May I ask how to override a function in javascript ? Thanks. Quote Link to comment Share on other sites More sharing options...
xerver Posted October 2, 2014 Share Posted October 2, 2014 Depends on how your are extending the Sprite prototype, need to see your code. Most likely something like this:function MySprite(texture) { PIXI.Sprite.call(this, texture);}MySprite.prototype = Objet.create(PIXI.Sprite);MySprite.prototype.constructor = MySprite;MySprite.prototype.updateTransform = function () { PIXI.Sprite.prototype.updateTransform.apply(this, arguments); // Do custom every-frame calculations.}; Quote Link to comment Share on other sites More sharing options...
bali33 Posted October 2, 2014 Author Share Posted October 2, 2014 Thank you ! 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.