I'm making a game, and I want to have a pause between one condition being true and an expression being run. The commented line below shows you where I want the pause, and the kind of pause I want is like this (which doesn't work):
while (bullet.yPos >= 0) {}; //Tried, failed So I want my code to stop while bullet.yPos is greater than or equal to 0, and then continue when bullet.yPos is less than 0.
bullet.hidden = true; //I want the pause here, and the line below to be executed when bullet.yPos is less than 0 bullet.hidden = false; How should I do this?
EDIT: Here is the relevant method:
check: function() { for (var i = 0; i < this.aliens.length; i++) { var item = this.aliens[i]; if ((bullet.lockedXPos >= item.xPos) && (bullet.lockedXPos <= item.xPos + this.size) && (bullet.yPos >= item.yPos) && (bullet.yPos <= item.yPos + this.size)) { item.hit = true; bullet.hidden = true; while (bullet.yPos >= 0) {}; bullet.hidden = false; } } },
while(true)). Decisions are based on logic. Within your main game loop check ifbullet.yPos < 0... if so apply whatever it is you're trying to do. If not, do nothing.Promisethat resolves when the value is appropriate.