added animate view
This commit is contained in:
57
haxework/gui/AnimateView.hx
Executable file
57
haxework/gui/AnimateView.hx
Executable file
@@ -0,0 +1,57 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxe.Timer;
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import haxework.gui.SpriteView;
|
||||
|
||||
class AnimateView extends SpriteView {
|
||||
|
||||
private var bitmap:Bitmap;
|
||||
public var frames(default, set):Array<BitmapData>;
|
||||
public var interval(default, set):Int;
|
||||
private var frame:Int;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
bitmap = new Bitmap();
|
||||
frames = [];
|
||||
frame = 0;
|
||||
interval = 200;
|
||||
content.addChild(bitmap);
|
||||
changeFrame();
|
||||
}
|
||||
|
||||
private function set_frames(value:Array<BitmapData>):Array<BitmapData> {
|
||||
if (frames != value) {
|
||||
frames = value;
|
||||
frame = 0;
|
||||
changeFrame(true);
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
|
||||
private function set_interval(value:Int):Int {
|
||||
if (interval != value) {
|
||||
interval = value;
|
||||
}
|
||||
return interval;
|
||||
}
|
||||
|
||||
private function changeFrame(?forse:Bool = false):Void {
|
||||
frame = ++frame % frames.length;
|
||||
bitmap.bitmapData = frames[frame];
|
||||
update();
|
||||
if (!forse) Timer.delay(function() changeFrame(false), interval);
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
if (contentSize && bitmap.bitmapData != null) {
|
||||
width = bitmap.bitmapData.width;
|
||||
height = bitmap.bitmapData.height;
|
||||
}
|
||||
super.update();
|
||||
bitmap.x = (width - bitmap.width) / 2;
|
||||
bitmap.y = (height - bitmap.height) / 2;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import haxework.gui.LabelView;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.ToggleButtonView;
|
||||
import haxework.gui.ProgressView;
|
||||
import haxework.gui.AnimateView;
|
||||
import haxework.gui.skin.ColorSkin;
|
||||
import haxework.gui.skin.BitmapSkin;
|
||||
import haxework.gui.skin.ButtonColorSkin;
|
||||
|
||||
Reference in New Issue
Block a user