as3垂直水平对齐

时间:2013-12-17 08:29:52

标签: actionscript-3 game-physics

我正在创建一个涉及水平和垂直水平滚动的平台游戏。该级别是基于图块的,由数组构建。除了角色之外的所有东西都是水平持有者mc的孩子。我的问题是跳跃后水平持有者的重新调整。最初,字符y值将在跳转期间更改,然后在其着陆的图块顶部对齐(循环切片,hittest,mc.y=tile[i].y-mc.height)。

现在我正在制作它,以便更改等级的y值,保持角色居中并允许垂直滚动的等级。如何在瓷砖击中角色后重新对齐水平持有者?

当角色未击中图块时,从enter_frame函数调用的基本跳转函数:

function charJump():void 
{
    if (! charJumping) {
        charJumping = true;
        jumpSpeed = jumpSpeedLimit * -1;
        lvlHolder.y -=  jumpSpeed;
    } else {
        if (jumpSpeed < 0) {
            jumpSpeed *=  1 - jumpSpeedLimit / 160;
            if (jumpSpeed > -jumpSpeedLimit/5) {
                jumpSpeed *=  -1;
            }
        }

        if (jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit) {
            jumpSpeed *=  1 + jumpSpeedLimit / 50;
        }

        lvlHolder.y -=  jumpSpeed;

        for (var i:int = 0; i<blockHolder.numChildren; i++) {
            var hitBlock:MovieClip = MovieClip(blockHolder.getChildAt(i));
            var trueY = hitBlock.localToGlobal(new Point(0,0));
            if (botBox.hitTestObject(hitBlock)) {
                if (jumpSpeed > 0 && charHolder.y<=trueY.y - (charHolder.getChildAt(0).height/2)) {
                    charJumping = false;
                    doubleJumping = false;
                    //lvlHolder.y = stage.stageHeight - lvlHolder.height;
                    charHolder.y = trueY.y - (charHolder.getBounds(this).y + charHolder.height - charHolder.y)+1;
                    charOnGround = true;
                    break;
                }
            }
        }
    }
}

0 个答案:

没有答案
相关问题