Please tell 500мс how to make the function run every time with a delay of 500мс (frameWidth / 2) != enemyDistance , after the function is closed.
var motionEnemy = function () { if (rightSid === true) { while ( (frameWidth / 2) != enemyDistance ) { console.log('step'); enemy.css({marginRight: enemyDistance + 'px'}); enemyDistance += STEP_LENGHT; setTimeout(motionEnemy,__self.GAME_TICK*); } }; setTimeout(motionEnemy(),__self.GAME_TICK);
whilereplace withif? - Maxim Timakov