为什么当淡入淡出效果起作用时,这种移动效果对我的精灵不起作用? [英] Why wont this move effect work on my sprites when the fade effect does?
问题描述
有人可以解释为什么这不起作用吗?在徽标后面有点装饰.
Could someone please explain why this doesn't want to work? It's a bit of decoration to go behind a logo.
当 dMove var 被注释掉时,我会在沿 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?
非常感谢,非常感谢!
乔希
推荐答案
好的,经过一番尝试后,我设法找到了解决方案,我非常感谢 Brian Bishop 的帮助,他成功地为我指出了正确的方向.
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.
正如 Brian 所建议的,只需输入 d
作为 UIComponent 而不是 sprite
就可以让 dMove
生效(我仍然不知道为什么这是因为 dFade
效果在它仍然是一个精灵时起作用).然而,每次添加 floatBG
(BG 是背景,添加所有 d UIComponents 的 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 元素是必要的,因为它是位于屏幕角落的徽标的一部分,看起来尽可能漂亮...
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...
最终我找到了下面的解决方案,它的关键是用 600 个虚拟 UIComponents 加载 floatBG
,然后在 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>
好吧,抱歉,如果这有点啰嗦,但有人可能会觉得它很有用...这是一个很好的效果(无论如何我都这么认为)
Ok, apologies if that was pretty long-winded, but someone may find it useful... it's a nice effect (I think so anyway)
我使用蒙版为 d 元素出现的点提供了一个清晰的边缘.或者,可以将它放在另一个对象后面,但如果像我这样,对象是一条宽度小于某些 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屋!