我尝试制作一个正方形网格,在那里我可以单独控制每个方块的颜色参数,即。让它们一个接一个地闪烁或同时闪烁。
我正在尝试使用tweens,使用for-loop运行参数。
下面的代码尝试同时闪烁所有方块,每秒一次。但由于某些原因,所有的方块都没有补间,只有一些方法。或者他们部分补间,有时他们根本没有补间。但是,模式不会重复。
同时这个太多的补间了吗? for循环是正确的方法吗?我应该使用MovieClips而不是Sprite吗?如果我想在非常快的阶段控制许多不同对象中的颜色,那么最好的方法是什么?
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.*;
import flash.events.*;
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.geom.ColorTransform;
import Math;
import flash.utils.Timer;
import flash.events.TimerEvent;
import resolumeCom.*;
import resolumeCom.parameters.*;
import resolumeCom.events.*;
public class LightGrid extends MovieClip
{
private var t1:Tween;
private var resolume:Resolume = new Resolume();
private var tempo:FloatParameter = resolume.addFloatParameter("Tempo", 0.6);
private var pad = 3;
private var dim = 20;
private var posX = 0 + pad;
private var posY = 0 + pad;
private var a:Number = new Number();
private var b:Number = new Number();
private var blk:Number = new Number();
var newCol:ColorTransform = new ColorTransform();
public function LightGrid()
{
resolume.addParameterListener(parameterChanged);
for (var b = 0; b < 16; b++)
{
posY = (b*dim) + (b*pad) + pad;
trace("New row");
for (var a = 0; a < 24; a++)
{
posX = (a*dim) + (a*pad) + pad;
// l = line, f = fill
var l:Sprite = new Sprite;
l.graphics.lineStyle(2, 0xFFFFF, 1);
l.graphics.drawRect(posX, posY, dim, dim);
l.name = "line_Row" + b + "Col" + a;
addChild(l);
var f:Sprite = new Sprite;
f.graphics.beginFill(0x990000, 1);
f.graphics.drawRect(posX, posY, dim, dim);
f.graphics.endFill();
f.name = "fill_Row" + b + "Col" + a;
addChild(f);
trace(getChildByName("fill_Row" + b + "Col" + a).name);
}
}
var myTimer:Timer = new Timer(1000, 100);
myTimer.addEventListener("timer", timerHandler);
myTimer.start();
}
public function timerHandler(event:TimerEvent):void {
flashTheLights();
}
public function parameterChanged(e:ChangeEvent):void
{
if (e.object == tempo)
{
}
}
public function flashTheLights():void
{
blk = 0;
for (var blk = 0; blk < (24/3); blk++)
{
for (var d = 0; d < 16; d++)
{
for (var c = (0+(3*blk)); c < (3+(3*blk)); c++)
{
newCol.redOffset=30-(35*blk);
newCol.blueOffset=200+(7*blk);
newCol.greenOffset=200;
trace(getChildByName("fill_Row" + d + "Col" + c).name);
var fill:Sprite = getChildByName("fill_Row" + d + "Col" + c) as Sprite;
fill.transform.colorTransform.alphaMultiplier = -255;
fill.transform.colorTransform = newCol;
trace("Run tween");
var myTween = new Tween(fill,'alpha',Regular.easeIn,1,0,0.3,true);
}
}
trace("Done!" + blk);
}
}
}
答案 0 :(得分:0)
我有点通过将精灵堆叠在动画片段下解决了这个问题,所以我只补充了几个元素而不是几十个或几百个
for (var k = 0; k < (grdX/ptrnSz); k++)
{
var ptrn:MovieClip = new MovieClip();
ptrn.name = "ptrn" + k;
addChild(ptrn);
ptrn.alpha = 0.01;
ptrnAm++;
for (var d = 0; d < grdY; d++)
{
posY = (d*dim) + (d*pad) + top;
for (var c = (0+(ptrnSz*k)); c < (ptrnSz+(ptrnSz*k)); c++)
{
posX = (c*dim) + (c*pad) + left;
// l = line, f = fill
var f:Sprite = new Sprite;
f.graphics.beginFill(0xFFFFFF, 1);
f.graphics.drawRect(posX-0.5, posY, dim, dim);
f.graphics.endFill();
f.name = "fill_Block" + k + "Row" + d + "Col" + c;
ptrn.addChild(f);
}
}
}
grdX = X轴的网格大小(多少列)
ptrnSz =包含精灵的动画片段的大小(多少列)
之后我只是用TweenMax补充动画片段,用getChildByName调用它们。