0

我的平台游戏引擎跳转功能有问题。我已将所有命中测试转移到关卡中的各个平台上,因此我不必为每个单独的平台编写内容。这样做的问题是,只有第一个添加到舞台的影片剪辑可以跳转到。如果 up 被按住,其他人只会让玩家沉入地板(因为他们应该 - 因为他不应该在那里,所以没有什么可以阻止他)。所以问题是跳转的检查没有在第二个块上正确注册。这是代码(对过多的 MovieClip(parent) 感到抱歉)

var playerRef:MovieClip = MovieClip(parent).player;

stage.addEventListener(Event.ENTER_FRAME, hitUpdate);
function hitUpdate(e:Event):void {
    if (playerRef.hitTestPoint(playerRef.x,this.y - (playerRef.height/2)) && playerRef.x + playerRef.width > this.x && playerRef.x < this.x + this.width && !MovieClip(parent).upDown) {
        MovieClip(parent).downMomentum = 0;
        playerRef.y = this.y - playerRef.height;
    }

    if (playerRef.hitTestPoint(playerRef.x,this.y + this.height) && playerRef.x + playerRef.width > this.x && playerRef.x < this.x + this.width) {
        MovieClip(parent).downMomentum = 0;
        playerRef.y = this.y + this.height + MovieClip(parent).gravity;
    }

    if (playerRef.hitTestPoint(this.x,playerRef.y) && playerRef.y + playerRef.height > this.y && playerRef.y < this.y + this.height) {
        MovieClip(parent).speed = 0;
        playerRef.x = this.x - playerRef.width;
    }

    if (playerRef.hitTestPoint(this.x + this.width,playerRef.y) && playerRef.y + playerRef.height > this.y && playerRef.y < this.y + this.height) {
        MovieClip(parent).speed = 0;
        playerRef.x = this.x + this.width;
    }

    if (playerRef.hitTestObject(this)) {
        MovieClip(parent).groundTouch = true;
    } else {
        MovieClip(parent).groundTouch = false;
    }
}

跳转功能是这样运行的:

stage.addEventListener(Event.ENTER_FRAME, updates);
function updates(e:Event):void{

    player.y += downMomentum;

    if(!groundTouch && downMomentum < downMomCap){
        downMomentum += gravity;
    }
    if(downMomentum > downMomCap){
        downMomentum = downMomCap;
    }

    if(upDown && !jumping && groundTouch){
        jumping = true;
        jumpTimer.reset();
        jumpTimer.start();
    }
}

jumpTimer.addEventListener(TimerEvent.TIMER, jumpTick);
function jumpTick(e:TimerEvent):void{
    if(downMomentum*-1 < downMomCap){
        downMomentum  -= jumpProg * jumpIncrement;
    }else{
        downMomentum = downMomCap * -1;
    }
    jumpProg -= 1;
}

jumpTimer.addEventListener(TimerEvent.TIMER_COMPLETE, jumpDone);
function jumpDone(e:TimerEvent):void{
    jumpTimer.stop();
    jumping = false;
    jumpProg = 5;
}

我只是找不到解决方案,尽管我怀疑这与它如何检查玩家接触平台有关。

4

0 回答 0