I am trying to implement "Snake" using crafty.js but I can't seem to get the snake entity to move just once in a second. How do I do this?
You could use the timeout method from Crafty core functions.
First argument is the function to be executed, second argument is the time in miliseconds
Crafty.c("Snake",{
init: ...
move: function() {
//code for movement
this.timeout(move, 1000);
}
});
or you can pass an anonymus function as argument
this.timeout(function() {
//code code coode
}, 1000);
source: http://craftyjs.com/api/Crafty-Core.html#-timeout
Sorry if i my English is bad
-
\$\begingroup\$ I must have missed this in the documentation. Thank you for pointing it out. \$\endgroup\$ – gnerkus Apr 17 '13 at 0:38