首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >addChild/init问题

addChild/init问题
EN

Stack Overflow用户
提问于 2014-07-13 17:30:06
回答 1查看 53关注 0票数 0

嘿,我正在做youtube上的“闪光气泡:使用TimelineMax的粒子系统”。我得到了这样的代码:

代码语言:javascript
复制
package
{
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

public class main extends Sprite
{
    private var BG:bg= new bg;
    private var start_btn:start_button= new start_button;

    private  var tl:TimelineMax= new TimelineMax();
    private var bubbleMax:Number = 50;


    public function main()
    {
        stage.addChild(BG);
        stage.addChild(start_btn);

        BG.y= (stage.stageWidth)/2;
        BG.x = (stage.stageWidth)/2;
        start_btn.x = (stage.stageWidth)/2;
        start_btn.y = (stage.stageHeight)/2;
        start_btn.addEventListener(MouseEvent.CLICK,StartGame);
    }
    private function StartGame(e:Event)
    {
        stage.removeChild(BG);
        stage.removeChild(start_btn);
        createBubble();

    }

    private function createBubble()
    {
        var Bubble:bubble= new bubble();
        Bubble.y=200;
        Bubble.x= randomRange(50,1100);
        Bubble.alpha= .5;
        addChild(Bubble);
    }


    private function randomRange(min:Number,Max:Number):Number
    {
        return min + (Math.random() * (Max - min));
    }

    private function init() 
    {
        for (var count:Number = 0; count<bubbleMax; count++)
        {
            createBubble();
        }
    }
    init();
}

}

start_button和气泡都是用flash制作的电影剪辑(还有一个as3类)我看到了50个气泡,但只能看到一个..感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2014-07-13 20:40:57

将StartGame函数更改为:

代码语言:javascript
复制
private function StartGame(e:Event)
{
    stage.removeChild(BG);
    stage.removeChild(start_btn);
    // Your init function is where you're creating all the bubbles. That's what the "for" loop is doing.
    init();
}

另外,不要像现在这样在底部调用init();。你的代码应该看起来像这样:

代码语言:javascript
复制
package
{
    import com.greensock.*;
    import com.greensock.easing.*;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class main extends Sprite
    {
        private var BG:bg= new bg();
        private var start_btn:start_button= new start_button();

        private  var tl:TimelineMax= new TimelineMax();
        private var bubbleMax:Number = 50;


        public function main()
        {
            stage.addChild(BG);
            stage.addChild(start_btn);

            BG.y= (stage.stageWidth)/2;
            BG.x = (stage.stageWidth)/2;
            start_btn.x = (stage.stageWidth)/2;
            start_btn.y = (stage.stageHeight)/2;
            start_btn.addEventListener(MouseEvent.CLICK,StartGame);
        }

        private function StartGame(e:Event)
        {
            stage.removeChild(BG);
            stage.removeChild(start_btn);
            init();
        }

        private function createBubble()
        {
            var Bubble:bubble= new bubble();
            Bubble.y=200;
            Bubble.x= randomRange(50,1100);
            Bubble.alpha= .5;
            addChild(Bubble);
        }

        private function randomRange(min:Number,Max:Number):Number
        {
            return min + (Math.random() * (Max - min));
        }

        private function init() 
        {
            for (var count:Number = 0; count<bubbleMax; count++)
            {
                createBubble();
            }
        }
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24721287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档