Actionscript 3 作为3个动作脚本

Actionscript 3 作为3个动作脚本,actionscript-3,Actionscript 3,我试图让我的EntityArray停止移动,一旦它击中屏幕的宽度和高度,如果有人能帮助我,它会很棒,然后将它的位置重置到中心,这是我的大学项目 private function keyDownHandler(evt:KeyboardEvent) { // Detect 'A' key for UP movement if(evt.keyCode == 65) { trace("A") //Move player left (using k

我试图让我的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;
}
//在当前函数的此行后添加if语句:
EntityArray[0].x=(EntityArray[0].x)-10;
//保护码
if(EntityArray[0].x Stage.width-EntityArray[0].width){
//注意:您需要从舞台上减去青蛙的宽度,以避免重置位置前青蛙大部分离开屏幕。
EntityArray[0].x=320;
}

您当前的代码不起作用了吗?您好,Brian,感谢您的代码添加了代码,并出现以下错误1119:通过引用静态类型类访问可能未定义的属性宽度。1119:通过静态类型类的引用访问可能未定义的属性宽度。@GamesUK My bad,它应该是带小写字母w的“宽度”。如果蛙式到达屏幕边缘//它将重置其位置(EntityArray[0],则如何为-x//执行此操作没有问题.x Hi Brian非常感谢您的帮助我如何在x轴上展开一个数组我有一个填充3项的var循环,需要在x位置展开//为(var h:int=1;h)创建一个心脏