AS 3动作脚本

时间:2019-03-22 16:17:48

标签: actionscript-3

我试图让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);
}

1 个答案:

答案 0 :(得分:1)

您可以在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;
}