Created
October 16, 2018 15:43
-
-
Save 01010111/602b267f3c8b6e059450912a8760a349 to your computer and use it in GitHub Desktop.
Heaps Animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h2d.Anim; | |
import h2d.Tile; | |
class Animation extends Anim | |
{ | |
var anims:Map<String, AnimData> = new Map(); | |
var tiles:Array<Tile>; | |
var current_anim:String = ''; | |
public function new(tiles:Array<Tile>) | |
{ | |
for (tile in tiles) | |
{ | |
tile.dx = -Std.int(tile.width * 0.5); | |
tile.dy = -Std.int(tile.height * 0.5); | |
} | |
super(tiles, 0); | |
this.tiles = tiles; | |
setPosition(tiles[0].width * 0.5, tiles[0].height * 0.5); | |
} | |
public function add(name:String, data:AnimData) anims.set(name, data); | |
public function play_anim(name:String, frame:Int = 0, force:Bool = false) | |
{ | |
if (!anims.exists(name)) | |
{ | |
LOG('No animation called $name!', WARNING); | |
return; | |
} | |
if (current_anim == name && !force) return; | |
current_anim = name; | |
play([for (i in anims[name].frames) tiles[i]], frame); | |
speed = anims[name].speed != null ? anims[name].speed : 0; | |
loop = anims[name].loop != null ? anims[name].loop : true; | |
} | |
} | |
typedef AnimData = | |
{ | |
frames:Array<Int>, | |
?speed:Int, | |
?loop:Bool, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment