AS3:汽车移动速度

时间:2014-11-15 11:36:00

标签: actionscript-3 flash

我在AS3开始了。我正在按照教程蛙游戏,你可以在这里查看完整的代码http://www.makeflashgames.com/tutorialsplus/tutorial-frogger.php。在函数startGame()中,我知道“speedX”是汽车在X方向上的移动速度。我尝试将speedX改为speedY,但没有任何反应,汽车只是不动。请帮我写一个移动汽车的功能跟随X和Y.或者请帮我说清楚...谢谢:)

public function startGame()
    {           
        timeElapsed = 0;
        totalTimer = 99;
        life = 3;
        p1speedX = 0;
        p1speedY = 0;
        gotoWin = false;
        gotoLose = false;
        standingOnLog = false;
        cars = new Array();
        logs = new Array();
        homes = new Array();
        logsYPos = new Array(115,165,215,265);
        carsYPos = new Array(365,415,465,515);

        setupGame();

        //Spawn Cars
        //Row 1
        for (var i=1; i<=2; i++)
        {
            var newCar = new Car();
            newCar.x = -300 * i;
            newCar.y = carsYPos[0];
            newCar.speedX = 150;
            cars.push(newCar);
            addChild(newCar);
        }

        //Row 2
        for (var i=1; i<=3; i++)
        {
            var newCar = new Car();
            newCar.x = (170 * i) + 500;
            newCar.y = carsYPos[1];
            newCar.speedX = -5;
            cars.push(newCar);
            addChild(newCar);
        }

        //Row 3
        for (var i=1; i<=3; i++)
        {
            var newCar = new Car();
            newCar.x = (-220 * i) + 100;
            newCar.y = carsYPos[2];
            newCar.speedX = 8;
            cars.push(newCar);
            addChild(newCar);
        }

        //Row 4
        for (var i=1; i<=3; i++)
        {
            var newCar = new Car();
            newCar.x = (200 * i) + 350;
            newCar.y = carsYPos[3];
            newCar.speedX = -5;
            cars.push(newCar);
            addChild(newCar);
        }

1 个答案:

答案 0 :(得分:0)

此功能不会移动汽车,只是设定速度。

查看第9部分,handleGameLogic(),以便进行移动。