Programmatic animation
Hi, all. I'm developing a carousel like swf, and have a problem with CPU usage. How it works: main swf loads 4 child swf's, every swf has it's own animation, then main swf positions child swfs on the stage: one swf in front and have no scale, other swf in back and every have its own scale ratio. When user clicks buttons swfs are moves along the triangle like trajectory, and when swfs stop movement the main swf changes background image to fit the front swf. So the problem: I've tried timer based animation, but it doesn't looks well, so I've changed to ENTER_FRAME event. Trajectory of movement is unusual, so I need to recalculate on enter_frame position of every loaded swf. My solution was to have an array with swfs and on enter frame:
public function onNext(event:Event):void {
if(_count < 24) {
for each(var c:ImageContainer in this._images) {
if(c.identifier==2) {
c.x += 11;
c.scaleX = c.scaleY += 0.01875;
c.y -= 2;
c._textFieldBottom.alpha -= .0417;
continue;
} else if(c.identifier == 1) {
c.x += 5;
c.scaleX = c.scaleY += 0.00625;
continue;
} else if(c.identifier == 0) {
c.x += 17;
c.scaleX = c.scaleY -= 0.01875;
c._textFieldBottom.alpha += .0417;
continue;
} else if(c.identifier == 3) {
c.x -= 33;
c.y += 2;
c.scaleX = c.scaleY -= 0.00625;
continue;
}
}
_count++;
} else {
_count = 0;
this.removeEventListener(Event.ENTER_FRAME, onNextTimer);
onNextComplete();
}
}
It does iteration through the array with swfs containers and calculates position of each, _count variable is for limit number of iterations (animation steps). And identifier variable is used as pointer - to know which swf where is located.
But this eats about 90% of cpu... yeah, I now it's terrible. Please advice somebody, may be there is less processor intensive aproach exists? Or may be I think in wrong way?