0
如何讓玩家在與物體接觸時停下來,但是當物體接觸物體的x側時,它仍然可以上下滑動,當物體接觸物體的y側時,它仍然可以滑動邊碰撞邊。as3 - 接觸物體時如何停止移動?
這是我的玩家運動代碼。
public function onKeyDown(event: KeyboardEvent): void
{
if (event.keyCode == Keyboard.D)
{
isRight = true;
}
if (event.keyCode == Keyboard.A)
{
isLeft = true;
}
if (event.keyCode == Keyboard.W)
{
isUp = true;
}
if (event.keyCode == Keyboard.S)
{
isDown = true;
}
}
public function onEnterFrame(event: Event): void
{
if (isRight)
{
x += 5;
}
if (isLeft)
{
x -= 5;
}
if (isUp)
{
y -= 5;
}
if (isDown)
{
y += 5;
}
}
你有沒有試過['obj.hitTestPoint()'](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/ 3/flash/display/DisplayObject.html#hitTestPoint())或['obj.hitTestObject()'](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject .html#hitTestObject())...? – akmozo
hittestobject .. – Crook