0

我正在用 Flash 构建一个自上而下(鸟瞰图)游戏,一个相当简单的概念,一个早期的塞尔达传说或最终幻想游戏。我已经建立了关卡,添加了角色并且可以移动,使用滚动相机,但有一个问题让我很烦恼。命中测试。

关卡是使用数组创建的——一个简单的 [1,1,1];数组,它检查数组中的值是否匹配,然后创建一个简单的方形 Sprite 并将其添加到包含每个项目的更大 Sprite 中。最后,玩家被添加到舞台上,并且可以使用箭头键进行控制。我将其用作运动系统:

stage.addEventListener(KeyboardEvent.KEY_DOWN, checkDown);
stage.addEventListener(KeyboardEvent.KEY_UP, checkUp);
stage.addEventListener(Event.ENTER_FRAME, update);

function checkDown(e:KeyboardEvent):void {
   switch (e.keyCode) {
    case 65 :
        leftDown = true;
        break;
    case 37 :
        leftDown = true;
        break;
    case 68 :
        rightDown = true;
        break;
    case 39 :
        rightDown = true;
        break;
    case 87 :
        upDown = true;
        break;
    case 38 :
        upDown = true;
        break;
    case 83 :
        downDown = true;
        break;
    case 40 :
        downDown = true;
        break;
}
}

function checkUp(e:KeyboardEvent):void {
switch (e.keyCode) {
    case 65 :
        leftDown = false;
        break;
    case 37 :
        leftDown = false;
        break;
    case 68 :
        rightDown = false;
        break;
    case 39 :
        rightDown = false;
        break;
    case 87 :
        upDown = false;
        break;
    case 38 :
        upDown = false;
        break;
    case 83 :
        downDown = false;
        break;
    case 40 :
        downDown = false;
        break;
}
}

function update(e:Event):void {
if (upDown) {
    if (genericHolder.y >= boundariesLevelOne[(room*4) - 4]) {
        genericHolder.y = boundariesLevelOne[(room*4) - 4];
        Player.y-=power;
    }
    if (genericHolder.y < boundariesLevelOne[(room*4) - 4]) {
        genericHolder.y+=power;
    }
    Player.Stand.visible = false;
    Player.Forwards.visible = false;
    Player.Rights.visible = false;
    Player.Lefts.visible = false;
    Player.Backwards.visible = true;
    playerDirection = 2;
}
if (downDown) {
    if (genericHolder.y <= boundariesLevelOne[(room*4) - 3]) {
        genericHolder.y = boundariesLevelOne[(room*4) - 3];
        Player.y+= power;
    }
    if (genericHolder.y > boundariesLevelOne[(room*4) - 3]) {
        genericHolder.y-=power;
    }
    Player.Stand.visible = false;
    Player.Backwards.visible = false;
    Player.Rights.visible = false;
    Player.Lefts.visible = false;
    Player.Forwards.visible = true;
    playerDirection = 1;
}
if (leftDown) {
    if (genericHolder.x >= boundariesLevelOne[(room*4) - 2]) {
        genericHolder.x = boundariesLevelOne[(room*4) - 2];
        Player.x -= power;
    }
    if (genericHolder.x < boundariesLevelOne[(room*4) - 2]) {
        genericHolder.x+=power;
    }
    Player.Stand.visible = false;
    Player.Backwards.visible = false;
    Player.Forwards.visible = false;
    Player.Rights.visible = false;
    Player.Lefts.visible = true;
    playerDirection = 4;
}
if (rightDown) {
    if (genericHolder.x <= boundariesLevelOne[(room*4) - 1]) {
        genericHolder.x = boundariesLevelOne[(room*4) - 1];
        Player.x += power;
    }
    if (genericHolder.x > boundariesLevelOne[(room*4) - 1]) {
        genericHolder.x-=power;
    }
    Player.Stand.visible = false;
    Player.Backwards.visible = false;
    Player.Forwards.visible = false;
    Player.Lefts.visible = false;
    Player.Rights.visible = true;
    playerDirection = 3;
}
if (!upDown && !downDown && !leftDown && !rightDown) {
    Player.Backwards.visible = false;
    Player.Forwards.visible = false;
    Player.Rights.visible = false;
    Player.Lefts.visible = false;
    Player.Stand.visible = true;
    Player.Stand.gotoAndStop(playerDirection);
}
if (Player.Stand) {
    Player.Stand.gotoAndStop(playerDirection);
     }
}

TL;DR 背景移动而不是玩家,移动由变量控制。

我怎样才能对我添加的任何精灵进行测试?目前,如果我尝试对特定 Sprite 进行 Hittest,它会再次测试整个 Sprite 持有者,而不是我想要的特定 Sprite。

4

1 回答 1

0

你在使用最热门的方法吗?

http://www.actionscriptmoron.com/AS3Tutorials/hittest-hittestobject/

你是什​​么意思它再次测试整个精灵持有者只是获取包含对象的引用并将其传递给 hittest 方法。它应该工作。

于 2012-10-15T15:51:55.417 回答