为什么在我的精灵惯于此招效果工作时淡入淡出效果呢? [英] Why wont this move effect work on my sprites when the fade effect does?

查看:177
本文介绍了为什么在我的精灵惯于此招效果工作时淡入淡出效果呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能有人请解释为什么不想工作?这是一个有点装饰去后面的标志。

Could someone please explain why this doesn't want to work? It's a bit of decoration to go behind a logo.

在dMove变量被注释掉了,我得到的广场淡入淡出随意点沿x = 78轴的相应行,但是当推出没有出现在所有...

When the dMove var is commented out I get the appropriate line of squares fading in and out at random spots along the x = 78 axis, but when introduced nothing appears at all...

private var floatBG:UIComponent = new UIComponent();

private function addDP(event:TimerEvent):void{  

            var dY:Number = 5+Math.ceil(Math.random()*60);
            var dSize:Number = Math.ceil(Math.random()*12);
            var dAlpha:Number = Math.random()*0.5 + 0.2
            var dDuration:Number = Math.ceil(Math.random()*5000) + 1000;

            var d:Sprite = new Sprite();
            d.graphics.beginFill(0x1C75BC,dAlpha);
            d.graphics.drawRect(78, dY, dSize,dSize);
            d.graphics.endFill();

            floatBG.addChild(d);

            var dMove:Move = new Move(d);
            dMove.xBy = 300;
            dMove.duration = dDuration;

            dMove.play();

            var dFade:Fade = new Fade(d);
            dFade.alphaFrom = 1;
            dFade.alphaTo = 0;
            dFade.duration = dDuration;

            dFade.play();

            this.addElement(floatBG);

        }

此外,什么是最好的/正确的方法破坏了精灵在每个周期的结束?

Also, what would be the best/correct method for destroying the sprites at the end of each cycle?

感谢很多提前,大量AP preciate了!

Thanks a lot in advance, massively appreciate it!

约什

推荐答案

好了,一点用玩了后,我设法找到一个解决办法,我真的AP preciated布赖恩主教的帮助下,谁管理,非常在正确的方向多点我。

Ok, so after a bit of playing around with it I managed to find a solution, I really appreciated Brian Bishop's help, who managed to very much point me in the right direction.

由于布赖恩建议,只需输入 D 作为在UIComponent宁精灵允许的 dMove 来的效果(我仍然不知道这是为什么,因为 dFade 影响工作时,它仍然是一个精灵)。但是加入 floatBG (BG为背景,在UIComponent中的所有对D的UIComponent加入到)每次是不必要的,所以我做了 this.addElement (floatBG)我的的creationComplete 功能的一部分

As Brian suggested, simply entering d as a UIComponent rather a sprite allowed the dMove to effect (I'm still not sure why this is, as the dFade effect worked when it was still a sprite). However adding the floatBG (BG being background, the UIComponent to which all the d UIComponents are added) each time was unnecessary, so I made this.addElement(floatBG) part of my creationComplete function

然后我遇到了这个问题,应用程序开始,以填补对D实例(D最初代表数据点的方式,这是一种效果的主题,我试图创建的,一缕缕他们),并逐渐减缓了应用程序如蜗牛。要不断添加D单元是必要的,因为它是,它位于屏幕的角落寻找为pretty的标志的一部分,我可以把它...

I then ran into the issue that the application began to fill with the d instances (d originally stood for "datapoint" by the way, which was kind of the theme of the effect which I was trying to create, a plume of them), and progressively slowed the application to a crawl. To continuously add d elements is necessary as it's part of the logo that sits in the corner of the screen looking as pretty as I can make it...

最后,我来到了以下的解决方案,它的关键是要载入 floatBG 600虚拟UIComponents的,然后与每个周期的 addDP 函数既增加移动 D UIComponent到 floatBG ,然后取出另一UIComponent过的儿童的总阵列,它含有

Eventually I came to the below solution, the crux of it was to load floatBG with 600 dummy UIComponents, and then with each cycle of the addDP function both add a moving d UIComponent to floatBG and remove another UIComponent off of the total array of children which it contains.

因此​​,最终它看起来是这样的:

Thus, in the end it looked something like this:

<?xml version="1.0" encoding="utf-8"?><s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init(event)">

<fx:Script>
    <![CDATA[

        import mx.core.DesignLayer;
        import mx.core.UIComponent;
        import mx.effects.effectClasses.MoveInstance;
        import mx.events.EffectEvent;
        import mx.events.FlexEvent;
        import mx.states.RemoveChild;

        import spark.effects.AnimateColor;
        import spark.effects.AnimateFilter;
        import spark.effects.Fade;
        import spark.effects.Move;
        import spark.effects.Rotate;
        import spark.effects.easing.Sine;

        private var floatBG:UIComponent = new UIComponent;

        private var floatColour:uint = 0x1C75BC

        protected function init(event:FlexEvent):void
        {   

            //Float BackGround set up
            floatBG.mask = floatMaskBlock;
            floatBG.depth = -1;

            this.addElement(floatBG);


            //Fill FloatBG with 600 filler elements
                for(var i:int=0; i<600; i++)
                {
                    var filler:UIComponent = new UIComponent;
                    floatBG.addChild(filler);
                }
            //Float Animation Timer

            var floatTimer:Timer = new Timer(1,0);
            floatTimer.addEventListener(TimerEvent.TIMER,DPstartup)
            floatTimer.start();

        private function DPstartup(event:TimerEvent):void
        {
            this.addDP(5,60)
            this.addDP(22,14);
            this.addDP(18,18);
        }

        private function addDP(yf:Number,yt:Number):void
        {   
            this.title.text = floatBG.numChildren.toString();

            var dY:Number = yf+Math.ceil(Math.random()*yt);
            var dXby:Number = Math.ceil(Math.random()*1000 + 50);
            var dSize:Number = Math.ceil(Math.random()*12);
            var dAlpha:Number = Math.random()*0.5 + 0.2
            var dMotionDuration:Number = Math.ceil(Math.random()*15000) + 1000;
            var dFadeDuration:Number = Math.random()*dMotionDuration;

            var d:UIComponent = new UIComponent;

            d.graphics.beginFill(floatColour,dAlpha);
            d.graphics.drawRect(78, dY, dSize,dSize);
            d.graphics.endFill();

            var dMove:Move = new Move(d);
            dMove.xBy = dXby;
            dMove.duration = dMotionDuration;
            dMove.easer = Linear;

            dMove.play();

            var dFade:Fade = new Fade(d);
            dFade.alphaFrom = dAlpha;
            dFade.alphaTo = 0;
            dFade.duration = dFadeDuration;

            dFade.play();

            floatBG.addChild(d);
            floatBG.removeChildAt(0);
        };
    ]]>
</fx:Script>

<fx:Declarations>       
    <s:Sine id="Sine"/>
    <s:Bounce id="Bounce"/>
    <s:Linear id="Linear"/>     
</fx:Declarations>

<s:Group x="88" width="1000" height="80" id="floatMaskBlock">
    <s:Rect width="100%" height="100%">
        <s:fill>
            <s:SolidColor color="0xffffff"/>
        </s:fill>
    </s:Rect>
</s:Group></s:Group>

好吧,如果这是pretty的啰嗦,但有人可能会发现它很有用...这是一个很好的效果(我是这么认为反正)道歉

Ok, apologies if that was pretty long-winded, but someone may find it useful... it's a nice effect (I think so anyway)

我用掩模,得到锐边,以在其对d元素出现的点。可替代地1可以只将其放置在另一对象后面,但如果像在我的情况下,对象是一个线宽度小于某些对d元件的尺寸,这样的掩模是必要的。

I use the mask to give a sharp edge to the point at which the d elements appear. Alternatively one could just place it behind another object, but if, as in my case, the object is a line of width less than the size of some of the d elements, such a mask is necessary.

色彩被声明为一个变量在一开始,我很可能会增加一个功能上的点击,或类似的东西改变它。

The colour is declared as a variable at the beginning as I'll likely add a function to change it on click, or something similar.

谢谢!

约什

这篇关于为什么在我的精灵惯于此招效果工作时淡入淡出效果呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆