主要代码(初始化):
package {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Init extends Sprite {
var parts:Array,
images:Array,
w:Number = 20,
h:Number = 80,
numParts:int = stage.stageWidth / w,
i:int,
imgCount:int = 0,
timer:Timer,
rc:Number = 0,
vr:Number = 10;
public function Init() {
init();
}
function init():void
{
parts = new Array();
images = new Array(new Img1(), new Img2());
for(i = 0; i < numParts; i++)
{
var img2:BitmapData = new BitmapData(w, h);
img2.copyPixels(images[imgCount], new Rectangle(i * w, 0, w, h), new Point());
var bitmap:Bitmap = new Bitmap(img2);
bitmap.x = -w / 2
var rect:Rect = new Rect();
rect.addChild(bitmap);
rect.x = i * w + w / 2;
addChild(rect);
parts.push(rect);
}
i = 0;
timer = new Timer(2000);
timer.addEventListener(TimerEvent.TIMER, onTick);
timer.start();
}
function onTick(e:TimerEvent):void
{
addEventListener(Event.ENTER_FRAME, onEnterFrame);
timer.stop();
}
function onEnterFrame(e:Event):void
{
rotate2();
}
function rotate2()
{
parts[i].rotationY += vr;
parts[i].rc += vr;
if(parts[i].rc >= 180)
{
parts[i].rc = 0;
parts[i].rotationY = 0;
i++;
if(i >= numParts)
{
i = 0;
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
timer.start();
}
}
else
if(parts[i].rc == 90)
{
parts[i].imgCount++;
if(parts[i].imgCount >= images.length){parts[i].imgCount = 0;}
var img2:BitmapData = new BitmapData(w, h);
img2.copyPixels(images[parts[i].imgCount], new Rectangle(i * w, 0, w, h), new Point());
var bitmap:Bitmap = new Bitmap(img2);
bitmap.x = -w / 2
parts[i].redraw(bitmap);
parts[i].rotationY = -90;
}
}
function rotate1()
{
for(i = 0; i < numParts; i++)
{
parts[i].rotationY += vr;
}
rc += vr;
if(rc == 180)
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
timer.start();
rc = 0;
}
else
if(rc == 90)
{
imgCount++;
if(imgCount >= images.length){imgCount = 0;}
for(i = 0; i < numParts; i++)
{
var img2:BitmapData = new BitmapData(w, h);
img2.copyPixels(images[imgCount], new Rectangle(i * w, 0, w, h), new Point());
var bitmap:Bitmap = new Bitmap(img2);
bitmap.x = -w / 2
parts[i].redraw(bitmap);
parts[i].rotationY = -90;
}
}
}
}
}
矩形类:
package {
import flash.display.Sprite;
import flash.events.Event;
public class Rect extends Sprite {
public var imgCount:int = 0,
rc:int = 0;
public function Rect() {
init();
}
private function init():void
{
}
public function redraw(bitmap):void
{
removeChildAt(0);
addChild(bitmap);
}
}
}
描述:
这里我有2个方法,rotate1 - 一次旋转所有矩形,而rotate2在旋转180度后旋转每个矩形,然后旋转下一个矩形,所以我要做的是从当前旋转最近的矩形,假设最近的 3 个矩形,它们从当前旋转一半的速度,我怎么能用这个代码来做到这一点..
ps:您可以通过导入一些图像来尝试此代码...