Я пытаюсь заставить свой EntityArray перестать двигаться, как только он достигнет ширины и высоты экрана, если кто-нибудь может мне помочь, это будет здорово, а затем сбрасывает его положение в центр, это для моего университетского проекта
private function keyDownHandler(evt:KeyboardEvent)
{
// Detect 'A' key for UP movement
if (evt.keyCode == 65)
{
trace("A")
//Move player left (using key 'A')
EntityArray[0].x = (EntityArray[0].x)-10;
}
//creating the Frog
var newfrog = new frog();
newfrog.x = 320;
newfrog.y = 220;
EntityArray.push(newfrog);
}






Вы можете поместить довольно простой защитный код в свой keyDownHandler:
//Add the if statement after this line in your current function:
EntityArray[0].x = (EntityArray[0].x)-10;
//Guard code
if (EntityArray[0].x <= 0) {
EntityArray[0].x = 320;
} else if (EntityArray[0].x > Stage.width - EntityArray[0].width) {
//Note: You need to subtract the frog's width from the stage to avoid having the frog be mostly off the screen before resetting the position.
EntityArray[0].x = 320;
}