Jump to content

Adding a callback to a ticker....with parameters?


peterje
 Share

Recommended Posts

Hi devs,

 

In my project I have a number of GameObjects, each of which have a sprite attribute which is a derivative class of Pixi.Sprite. That doesn't really matter but just some background. Here's the issue:

 

  public startGame(): void {
    this.running = true
    this.app.ticker.start()
    for (const go of this.gameObjects) {
      go.sprite.dragDisable();
      go.sprite.start()
      this.app.ticker.add(go.sprite.update, go.sprite) // this is the problem
    }
  }

 

It is important that I can pass in go.sprite in as a context!

Each of my sprites have an update method, but it takes in a delta parameter:

update(delta: number): void;

 

So how can I add these callbacks to my ticker but pass in delta time?

 

Thanks

Peter

 

Link to comment
Share on other sites

It looks correct. Doesn't the delta get passed or what is the issue? You are adding a function that has delta parameter to ticker with the context of the sprite so it should work.  

Edited by Exca
Fixed typo
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...