MrKnubbles Posted April 13, 2016 Share Posted April 13, 2016 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); }}); Quote Link to comment Share on other sites More sharing options...
LinkTree Posted April 14, 2016 Share Posted April 14, 2016 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 Quote Link to comment Share on other sites More sharing options...
SkyzohKey Posted April 15, 2016 Share Posted April 15, 2016 @MrKnubbles You're using PandaJS v1, which is pretty much dead. Let' switch to PandaJS v2. You can take a look at the following links that got updated for v2: New PandaJS website PandaJS docs v2 PandaJS playground v2 Hope you'll like Panda Quote Link to comment Share on other sites More sharing options...
MrKnubbles Posted April 15, 2016 Author Share Posted April 15, 2016 Sorry. I just downloaded what was on the Panda.js website. I didn't see any versions, just a single download. Quote Link to comment Share on other sites More sharing options...
MrKnubbles Posted April 15, 2016 Author Share Posted April 15, 2016 I did find out that my issue was not because of the timer itself. It was the way my object was created. I was trying to access the wrong property. 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.