arun Posted May 19, 2017 Share Posted May 19, 2017 dear friends, I don't understand the 2 lines of code below. please help me if (this.time.now > shootTime) { nut = nuts.getFirstExists(false); } Link to comment Share on other sites More sharing options...
scheffgames Posted May 19, 2017 Share Posted May 19, 2017 A context of the above lines would be useful for understanding your question. this.time.now - "this" refers to the JS context so it might be different depending on where you use it. nuts.getFirstExists(false) - seems like a function that gets an object (nut). Link to comment Share on other sites More sharing options...
arun Posted May 19, 2017 Author Share Posted May 19, 2017 but, this.time.now means which time it indicate? Link to comment Share on other sites More sharing options...
scheffgames Posted May 19, 2017 Share Posted May 19, 2017 If you're using Phaser time then it will probably be (never used it myself so I might be wrong) a certain increasing value that can be used to measure how much time elapsed since a certain event. You don't really care about the initial value - all you need to know it's displayed in milliseconds and it increments accordingly. http://phaser.io/docs/2.4.6/Phaser.Time.html#now So at a certain point in your code you could say: var shootTime = game.time.now; Later in code you could check if a certain amount if time elapsed like this (checks if 1000 milliseconds have passed and does something): var mSeconds = 1000; if( game.time.now > (shootTime + mSeconds)){ //do stuff } or var shootTime = game.time.now + 1000;//stores the current time + 1000 milliseconds if(game.time.now > shootTime){ //do something } Like I said, you took those two lines out of the context so I can't really be sure to what those variables are pointing. Link to comment Share on other sites More sharing options...
Recommended Posts