Flash游戏开发AS3

时间:2011-03-10 11:53:14

标签: flash actionscript-3

我正在使用Flash AS3开发一款游戏,其中有多个物品掉落,必须使用鼠标在底部捕捉它。

只是想向你简要介绍游戏。

这是类似游戏的链接:http://www.playitontheweb.com/games/Catch-Falling-Fruit-game.htm

At frame 1 > Preloader
At frame 2 > Game front page.
At frame 3 > Game introduction.
At frame 4 > user will b playing the game.
At frame 5 > Final Score. 

这就是我想要在功能方面做到的。

这是脚本脚本(AS3),它在所有帧中播放游戏。从1到5,我不想要:请帮助......

package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
import flash.utils.getDefinitionByName;

public class CatchingGame extends MovieClip {
    var catcher:Catcher;
    var nextObject:Timer;
    var objects:Array = new Array();
    var score:int = 0;
    const speed:Number = 7.0;

    public function CatchingGame() {
        catcher = new Catcher();
        catcher.y = 350;
        addChild(catcher);
        setNextObject();
        addEventListener(Event.ENTER_FRAME, moveObjects);
    }

    public function setNextObject() {
        nextObject = new Timer(1000+Math.random()*1000,1);
        nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
        nextObject.start();
    }

    public function newObject(e:Event) {
        var goodObjects:Array = ["Circle1","Circle2"];
        var badObjects:Array = ["Square1","Square2"];
        if (Math.random() < .5) {
            var r:int = Math.floor(Math.random()*goodObjects.length);
            var classRef:Class = getDefinitionByName(goodObjects[r]) as Class;
            var newObject:MovieClip = new classRef(); 
            newObject.typestr = "good";
        } else {
            r = Math.floor(Math.random()*badObjects.length);
            classRef = getDefinitionByName(badObjects[r]) as Class;
            newObject = new classRef(); 
            newObject.typestr = "bad";
        }
        newObject.x = Math.random()*500;
        addChild(newObject);
        objects.push(newObject);
        setNextObject();
    }

    public function moveObjects(e:Event) {
        for(var i:int=objects.length-1;i>=0;i--) {
            objects[i].y += speed;
            if (objects[i].y > 400) {
                removeChild(objects[i]);
                objects.splice(i,1);
            }
            if (objects[i].hitTestObject(catcher)) {
                if (objects[i].typestr == "good") {
                    score += 5;
                } else {
                    score -= 1;
                }
                if (score < 0) score = 0;
                scoreDisplay.text = "Score: "+score;
                removeChild(objects[i]);
                objects.splice(i,1);
            }
        }

        catcher.x = mouseX;

    }
}
}

还想问一下,我们可以在60秒内添加一个计时器吗? 一旦计时器结束,它就会转到最后一帧以显示最终得分。

2 个答案:

答案 0 :(得分:0)

  • 致电stop()以保持在当前帧内,调用nextFrame()以前进到下一个场景
  • 全局函数getTimer()为您提供从swf启动传递的毫秒数,您可以使用它来测量时间。

答案 1 :(得分:0)

使用gotoAndStop()转到所需的帧并停在那里。我建议命令over stop()只是因为它将帧更改和停止行为捆绑成一个;否则他们是一回事。