简单点&生活显示不正确

时间:2013-12-28 18:27:18

标签: actionscript-3 actionscript adobe flash

所以我正在研究这个简单的游戏,你可以躲避坠落的巨石。每当一块巨石没有击中你(到达下面的y坐标),你就会得到30分。当一块巨石 击中你时,你会失去生命。不幸的是,它似乎会出现 看似 无法预测。

链接以测试游戏:http://fozgamez.com/a (只有1p鼠标工作)

我不知道如何解决问题,因为我无法弄清楚问题是如何/何时发生的。

第二个场景的代码(带规则的场景):

import flash.events.MouseEvent;

stop();
var livesSelected:Number;

m1Select.addEventListener(MouseEvent.MOUSE_UP, m1Selected)
function m1Selected (e:MouseEvent)
{
    livesSelected = 01;
    gotoAndStop(3);
}

m3Select.addEventListener(MouseEvent.MOUSE_UP, m3Selected)
function m3Selected (e:MouseEvent)
{
    livesSelected = 03;
    gotoAndStop(3);
}

m5Select.addEventListener(MouseEvent.MOUSE_UP, m5Selected)
function m5Selected (e:MouseEvent)
{
    livesSelected = 05;
    gotoAndStop(3);
}

m9Select.addEventListener(MouseEvent.MOUSE_UP, m9Selected)
function m9Selected (e:MouseEvent)
{
    livesSelected = 09;
    gotoAndStop(3);
}

第三场比赛的代码(你真正参加比赛的地方):

import flash.events.Event;
import flash.events.TouchEvent;
import flash.events.MouseEvent;
import flash.utils.Timer;
var points:int = 0;
var lifeTimer:Timer = new Timer(1000, 1)
var lives:Number = livesSelected;

livesText.text = lives.toString();
pointsText.text = points.toString();


lifeTimer.stop()

stage.addEventListener(Event.ENTER_FRAME, enterFrame);
function enterFrame(e:Event){
        mChar.x = mouseX;
        mChar.y = mouseY;



        b1.y += 20;
        b2.y += 40;
        b3.y += 15;
        b4.y += 25;
        b5.y += 20;
        bFast.y += 50;

        if(mChar.y <= 20)
        {
            mChar.y = 20;
        }
        if(mChar.x >= 700)
        {
            mChar.x = 700;
        }
        if(mChar.y <= 0)
        {
            mChar.y = 700;
        }

        if(b1.y >= 730) {
            b1.y = (Math.random() + .001) * -200;
            b1.x = (Math.random() + .001) * 700;
            points += 15;
        }

        if(b2.y >= 730) {
            b2.y = (Math.random() + .001) * -200;
            b2.x = (Math.random() + .001) * 700;
            points += 30;
        }
        if(b3.y >= 730) {
            b3.y = (Math.random() + .001) * -200;
            b3.x = (Math.random() + .001) * 700;
            points += 15;
        }
        if(b4.y >= 730) {
            b4.y = (Math.random() + .001) * -200;
            b4.x = (Math.random() + .001) * 700;
            points += 15;
        }
        if(b5.y >= 730) {
            b5.y = (Math.random() + .001) * -200;
            b5.x = (Math.random() + .001) * 700;
            points += 15;
        }
        if(bFast.y >= 730) {
            bFast.y = (Math.random() + .001) * -200;
            bFast.x = (Math.random() + .001) * 700;
            points += 15;
        }

if(!lifeTimer.running) {
        livesText.text = lives.toString();
        mInvin.x = -66;
        mInvin.y = 560;
        pointsText.text = points.toString();

            if(mChar.hitTestObject(b1)) {
            lives--;
            livesText.text = lives.toString();
            lifeTimer.start();

            }
            if(mChar.hitTestObject(b2)) {
            lives--;
            livesText.text = lives.toString();
            lifeTimer.start();
            }
            if(mChar.hitTestObject(b3)) {
            lives--;
            livesText.text = lives.toString();
            lifeTimer.start();
            }
            if(mChar.hitTestObject(b4)) {
            lives--;
            livesText.text = lives.toString();
            lifeTimer.start();
            }
            if(mChar.hitTestObject(b5)) {
            lives--;
            livesText.text = lives.toString();
            lifeTimer.start();
            }
            if(mChar.hitTestObject(bFast)) {
            lives--;
            livesText.text = lives.toString();
            lifeTimer.start();  
            }
                if(lives <= 0)
                    {
                    gotoAndStop(7);
                    }
        }

            if(lifeTimer.running)
            {
                mInvin.x = mChar.x;
                mInvin.y = mChar.y;
            }

        }

感谢阅读:我知道这是一个难以理解的问题,所以感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您的问题来自我的代码,是您的事件监听器。我不知道你在第7帧上有什么代码,但是除非你删除事件监听器,否则它们将继续监听和运行代码,即使你已经在时间线上向前移动了播放头(例如,在调用gotoAndStop()时)