Jump to content

addTimer not working


MrKnubbles
 Share

Recommended Posts

Hello. I've been trying to add a timer to my game and have followed all the examples precisely and it will not work.

I'm creating an object and want the object to do something every second. If I use this.addTimer, I get an error saying this.addTimer is not a function. If I use game.scene.addTimer, I get no errors but the code inside never triggers.

 

Here is an example:

 Crate = game.Class.extend({
        init: function()
        {            game.scene.addTimer(1000, function() { console.log("timer"); }, true); }});

Link to comment
Share on other sites

What engine version? I tested in v2 and game.scene.addTimer(1000, function() { console.log("timer"); works fine.

The reason this.addTimer didn't work in your example is because this refers to the Class class you are extending and it doesn't have an addTimer method.

if you wanted your class to have an addTimer method you could extend the Container class instead, or use the Timer class in your own class in a similar way to how the Container/Scene classes are using it.

http://ekelokorpi.github.io/panda.js-site/engine/docs/files/src_engine_scene.js.html#l131

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