Jump to content

How to call a function once per frame ? Like an actionscript onEnterFrameEvent


Recommended Posts

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

Link to comment
Share on other sites

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.};
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.

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.


  • Recently Browsing   0 members

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