[client] added AniamteBundle

This commit is contained in:
2018-02-16 17:57:43 +03:00
parent 1ae84cf5a8
commit 52a4e44e47
10 changed files with 126 additions and 88 deletions

View File

@@ -6,6 +6,11 @@ import flash.display.Bitmap;
import flash.display.BitmapData;
typedef Frame = {
var image:BitmapData;
var length:Int;
}
class Animate extends Bitmap {
private static var timer:Timer;
@@ -27,21 +32,29 @@ class Animate extends Bitmap {
}
public var playing(default, set):Bool;
public var frames(default, set):Array<BitmapData>;
public var frames(default, set):Array<Frame>;
private var sequence:Array<BitmapData>;
private var index:Int;
public function new(?frames:Array<BitmapData>) {
public function new(?frames:Array<Frame>) {
super(null, PixelSnapping.AUTO, true);
this.frames = frames == null ? [] : frames;
init();
instances.push(this);
}
public function set_frames(value:Array<BitmapData>):Array<BitmapData> {
public function set_frames(value:Array<Frame>):Array<Frame> {
sequence = [];
index = 0;
if (value != null) {
frames = value;
bitmapData = frames[0];
index = 0;
for (frame in frames) {
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
}
bitmapData = sequence[0];
} else {
bitmapData = null;
}
return frames;
}
@@ -54,10 +67,10 @@ class Animate extends Bitmap {
}
private function update():Void {
if (++index >= frames.length) {
if (++index >= sequence.length) {
index = 0;
}
var nextBitmapData = frames[index];
var nextBitmapData = sequence[index];
x -= (nextBitmapData.width - bitmapData.width) / 2;
y -= (nextBitmapData.height - bitmapData.height) / 2;
bitmapData = nextBitmapData;