function ProcessCollisions():void{
//respawn if player died
if(percentHP == 0){
Player.x = _startMarker.x;
Player.y = _startMarker.y;
Gun.x = Player.x;
Gun.y = Player.y - 45;
_boundaries.x = 0;
_boundaries.y = 0;
Player.vy = 0;
currentHP = maxHP;
}
//when Player is Falling
if(Player.vy > 0){
//Otherwise process collisions of boundaires
var collision:Boolean = false;
if(_boundaries.hitTestPoint(Player.x, Player.y, true)){collision = true;}
if(collision == true){
while(collision == true){
Player.y -= 0.1;
Gun.y -= 0.1;
collision = false;
if(_boundaries.hitTestPoint(Player.x, Player.y, true)){collision = true;}
}
trace("Collision is " + collision);
currentHP -= Player.vy * .1
Player.vy = 0;
Gun.vy = 0;
JumpCount = 0;
}
}
}
我的碰撞处理在上面......我有这个问题,即使我与 _boundaries 内的对象发生碰撞,碰撞布尔值也会不断返回为假。当 while 循环不断将玩家拉出边界并且玩家似乎无限陷入其中时,它会在我的玩家身上产生震动效果......有人可以帮忙吗?同样在由 Enter Frame Timer 调用的 Frame 处理程序中,我对 Player.vy 进行了更多更改,如下所示
function FrameHandler(e:Event):void{
//If Statements to slow character
if(aKeyPressed == false && Player.vx > 0){
Player.vx -= 1
}
else if(dKeyPressed == false && Player.vx < 0){
Player.vx += 1
}
//Gravitates Player
Player.vy += 1.5;
//Controls arrays of bullets for Weapons
//Process Collisions
ProcessCollisions();
//Scroll Stage
scrollStage();
//Attunes for multiple keypresses
MultipleKeypresses();
//Keeps Gun attached to Players Arm
Gun.x = Player.x
Gun.y = Player.y - 45;
if(sKeyPressed){
Gun.y = Player.y - 13;
Gun.x = Player.x + 8;
}
//Checks Health
updateHealthBar()
//move Player and Gun
Gun.y += Player.vy;
Gun.x += Player.vx;
Player.x += Player.vx;
Player.y += Player.vy;
}