我正在建立一個自上而下(鳥瞰)遊戲的閃光燈,一個相當簡單的概念,一個早期的塞爾達傳說或最終幻想遊戲。我已經建立了關卡,並且角色添加和移動,帶有滾動相機,但是有一個問題讓我感到困擾。 Hittesting。Hittesting對一個級別建設陣列
該級別使用數組創建 - 一個簡單的[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背景移動而不是玩家,移動由變量控制。
如何對我添加的任何精靈進行Hittest測試?目前,如果我嘗試對特定的Sprite進行Hittest測試,它會再次測試整個Sprite持有者,而不是我想要的特定Sprite。任何幫助非常感謝,謝謝。
它並沒有針對精靈持有者中的單個對象進行測試,僅針對整個事情。 –
我不能看到你的代碼示例中的任何命中testig,你可以請更新與您嘗試對單個對象執行命中測試 – Luis