Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
    
I must have missed this in the documentation. Thank you for pointing it out. –  gnerkus Apr 17 '13 at 0:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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