Actionscript 3 绿石吐温阿尔法
尝试使用GreenSock在AS3中的Actionscript 3 绿石吐温阿尔法,actionscript-3,alpha,tween,flash-cs6,gsap,Actionscript 3,Alpha,Tween,Flash Cs6,Gsap,尝试使用GreenSock在AS3中的图形对象的alpha之间切换,但函数不起作用。尝试在2秒内从alpha 0过渡到0.7。fromTo()方法也不起作用。我不想这样做,但我必须使用增量for循环来完成吗?-因为这不会让我控制tween的时间 public function overlayBox():void { var overlaySquare:Sprite = new Sprite(); overlaySquare.graphics.beginFill(0x00000
图形对象的alpha之间切换,但函数不起作用。尝试在2秒内从alpha 0过渡到0.7。fromTo()代码>方法也不起作用。我不想这样做,但我必须使用增量for循环来完成吗?-因为这不会让我控制tween的时间
public function overlayBox():void {
var overlaySquare:Sprite = new Sprite();
overlaySquare.graphics.beginFill(0x00000);
overlaySquare.graphics.drawRect(0, 0, displayRes, displayRes);
overlaySquare.graphics.endFill();
overlaySquare.x = xScreenPos;
overlaySquare.y = yScreenPos;
TweenMax.from(overlaySquare, 2, {autoAlpha:0});
TweenMax.to(overlaySquare, 2, {autoAlpha:0.7});
addChild(overlaySquare);
trace("overlaySquare index: " + getChildIndex(overlaySquare));
}
编辑:我已将TweenMax函数从上面替换为以下内容,从而修复了从alpha 0到0.7的淡入度:
overlaySquare.alpha = 0;
TweenMax.to(overlaySquare, 5, {alpha:0.7});
然而,当alpha-tween与程序的其余部分一起运行时,它有一个问题。当你看到它的时候,二者会“闪烁”并立即变为0.7(看起来像是从0“跳跃”到0.7)。问题已被隔离到在overlybox()之后调用的函数代码>程序概述:使用loader加载图像。在加载器内部,有一个myTimer.start()代码>。这用于在加载映像后运行程序的其余部分。overlybox()
是第一个遵循并运行良好的方法。下一个方法,textAnimation()代码>,是破坏它的原因,我不知道为什么:
public function textAnimation():void {
//set text format
textFormat.font = "Helvetica Neue Light";
textFormat.size = 28;
textFormat.bold = false;
textFormat.color = 0xFFFFFF;
//textFormat.letterSpacing = 5;
//set text size
var size18bold:TextFormat = new TextFormat();
size18bold.size = 36;
size18bold.bold = true;
// pass text format
textOne.defaultTextFormat = textFormat;
textTwo.defaultTextFormat = textFormat;
var xScreenPosStart:Number = xScreenPos + 440;
var xScreenPosEnd:Number = xScreenPos - 300;
textOne.text = "Blah blah blah";
textOne.autoSize = TextFieldAutoSize.LEFT;
textOne.x = xScreenPosStart;
textOne.y = yScreenPos + 240;
TweenMax.to(textOne, 14, {x:xScreenPosEnd, ease:SlowMo.ease.config(1, 0), repeat:-1});
textTwo.text = "Blah blah blah";
textTwo.autoSize = TextFieldAutoSize.LEFT;
textTwo.x = xScreenPosStart;
textTwo.y = yScreenPos + 140;
TweenMax.to(textTwo, 12, {x:xScreenPosEnd, ease:SlowMo.ease.config(1, 0), repeat:-1, delay:4});
//add to stage
addChild(textOne);
trace("textOne index: " + getChildIndex(textOne));
addChild(textTwo);
trace("textTwo index: " + getChildIndex(textTwo));
textOne.setTextFormat(size18bold);
}
给出alpha的初始值,并仅使用tweenMax.To
你激活自动alpha插件了吗?如果没有,那就用
import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.AutoAlphaPlugin;
//activation is permanent in the SWF, so this line only needs to be run once.
TweenPlugin.activate([AutoAlphaPlugin]);
如果您不需要自动alpha,那么只需使用alpha属性
我试过这个:
private function _Show() : void {
var overlaySquare:Sprite = new Sprite();
overlaySquare.graphics.beginFill(0x00000);
overlaySquare.graphics.drawRect(0, 0, 200, 200);
overlaySquare.graphics.endFill();
overlaySquare.x = 100;
overlaySquare.y = 100;
TweenMax.to(overlaySquare, 2, {alpha:0.7});
addChild(overlaySquare);
trace("overlaySquare index: " + getChildIndex(overlaySquare));
}
这是可行的。手动设置alpha,而不是使用TweenMax.from
overlaySquare.alpha = 0;
TweenMax.to( overlaySquare, 2, { alpha : .7 } );
如果您的意思是overlysquare.graphics.beginll(0x00000,0)编码>和TweenMax.to(叠加平方,2,{autoAlpha:0.7})代码>,我以前试过这个。alpha通道永远保持在0,不会改变。是的,我已经导入并激活了插件,但它不会改变。我试过只用alpha,但也不行。同样在这种情况下,alpha
和autoAlpha
之间有什么不同?阅读这里:关于autoAlpha我用我的答案中提到的alpha值重试了你的代码,效果非常好。当你说这个方法不起作用时,你是说你没有看到添加的精灵,还是说你看到了精灵但没有看到吐温呢?只是再次尝试了一下,发现了一些问题。当独立运行时,会发生这样的情况:它从和alpha介于1到0.7之间,而不是介于0到0.7之间。当在显示图像上作为覆盖运行时:它以1的alpha绘制,并立即“闪烁”您是否尝试使用alpha而不是autoalpha插件我尝试将其更改为alpha
,而不是像上面那样使用autoalpha
,但所做的只是在图形绘制时将其设置为0.7(没有tween)。当您将其添加到其父级时,父级是否已上台?Tween不会等你把它加入舞台。当你呼叫它时,它立即开始。因此,如果您随后将其添加到stage,它看起来就像是在alpha==.7处添加的。问题受到在overlayBox()之后运行的函数的影响;它自身以及在displayImage()之后运行时都会变好;用作覆盖层。我会把它编辑到我的帖子里。