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

  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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.