当玩家跳跃时,敌人也会跳跃(敌人和玩家共享同一个父级)

时间:2014-04-25 15:04:09

标签: actionscript-3 flash

我的游戏中存在问题。

我在舞台上有两个对象延伸到同一个类。

事情是,当玩家跳跃时,地面向下移动,敌人因重力进入而坠落。

    private function scrollStage():void
    {
        if (lastPosX != lastPosX)
        {
            canScrollStage = false;
        }
        else if (lastPosX == lastPosX)
        {
            canScrollStage = true;
        }

        if (canScrollStage)
        {
            if (rightKey)
            {
                lookingRight = true;
                if (canParallaxRight)
                {
                    //trees.x -=  0.6;
                    //sky.x -= 1.3;
                }
                else
                {
                    //sky.x -= 0.4;
                }                   



            }
            else if (leftKey)
            {
                lookingLeft = true;
                if (canParallaxLeft)
                {
                    //trees.x +=  0.6;
                //  sky.x += 1.3;
                }
                else
                {
                    //sky.x -= 0.4;
                }                   
            }
            else
            {
                //sky.x -= 0.4;
            }
            for (var b:int = 0; b < childrenOnStage; b++)
            {
                if (getChildAt(b).name == "enemy" || getChildAt(b).name == "enemyRed" || getChildAt(b).name == "knife" || getChildAt(b).name == "ground")
                {
                    getChildAt(b).x += (stage.stageWidth * 0.5) - character.x;
                        //getChildAt(b).y += - character.y;
                }
            }

            //ground.x += (stage.stageWidth * 0.5) - character.x;
        }
        else
        {
            //sky.x -=  0.8;
        }

        // do this last, everything moves around object

        lastPosX = character.x;

        // Set the camera coordinates to the char coordinates.
        //camera.x = -
        // Adjust the world position on the screen based on the camera position.
        //ground.x = -camera.x + (stage.stageWidth / 2);
        camera.y = Math.round(character.y);


        for (var d:int = 0; d < childrenOnStage; d++)
        {
            if (getChildAt(d).name == "ground")
            {
                getChildAt(d).y = -camera.y  + stage.stageHeight;//+ (stage.stageHeight / 2);
            }

        }
        //ground.y = -camera.y + (stage.stageHeight / 2);

        character.x = stage.stageWidth * 0.5;

    }

camera.y = character.y;

因为他们共享同一个班级,所以敌人往往会跳起来,因为地面被推倒了。

关于我如何解决这个问题的任何提示,所以敌人和地精一起下来?

许多人说首先移动角色,然后移动地面。 好吧,请检查一下。

私有函数processMovement():void         {

        if (upKey)
        {

            if (climbDontJump)
            {
                character.yV = 0;
                character.y -= 2;;

            }
            else
            {
                character.jumpUp();
            }
            //character.jumpUp();
        }



        if (attackKey)
        {
            if (rightKey)
            {
                canParallaxRight = false;
                canParallaxLeft = false;
            }
            else if (leftKey)
            {
                canParallaxRight = false;
                canParallaxLeft = false;
            }
            character.attack();
        }
        else
        if (defendKey)
        {
            if (rightKey)
            {
                canParallaxRight = false;
                canParallaxLeft = false;
            }
            else if (leftKey)
            {
                canParallaxRight = false;
                canParallaxLeft = false;
            }

            character.defend();
        }
        else
        if (rightKey)
        {
            character.moveRight();
            lookingRight = true;
            lookingLeft = false;
        }
        else
        if (leftKey)
        {
            lookingLeft = true;
            lookingRight = false;
            character.moveLeft();
        }



        if (!leftKey && !rightKey && !upKey &&!defendKey && !attackKey)
        {
            character.dontMove();
        }

    }

我正在移动角色。

然后这段代码不会移动容器吗?

        if (lastPosX != lastPosX)
        {
            canScrollStage = false;
        }
        else if (lastPosX == lastPosX)
        {
            canScrollStage = true;
        }

这两个已经完成了

        lastPosX = character.x;
        character.x = stage.stageWidth * 0.5;

1 个答案:

答案 0 :(得分:0)

解决问题的简单方法是更改​​代码,以便在角色跳跃时敌人和地面向下移动。 Moynul,我也非常同意itcouldevenbeaboat,正常移动角色然后相应地定位其他一切。