浏览代码

Merge pull request #140 from motion-twin/master

Dear Mr Cannasse
Nicolas Cannasse 9 年之前
父节点
当前提交
28d419ee49
共有 6 个文件被更改,包括 49 次插入2 次删除
  1. 8 1
      h2d/SpriteBatch.hx
  2. 5 0
      h2d/Tile.hx
  3. 5 0
      h2d/TileGroup.hx
  4. 26 0
      hxd/Key.hx
  5. 4 0
      hxd/res/Any.hx
  6. 1 1
      hxd/res/Sound.hx

+ 8 - 1
h2d/SpriteBatch.hx

@@ -27,6 +27,7 @@ class BatchElement {
 	public var a : Float;
 	public var t : Tile;
 	public var alpha(get,set) : Float;
+	public var visible : Bool;
 	public var batch(default, null) : SpriteBatch;
 
 	var prev : BatchElement;
@@ -35,6 +36,7 @@ class BatchElement {
 	public function new(t) {
 		x = 0; y = 0; r = 1; g = 1; b = 1; a = 1;
 		rotation = 0; scale = 1;
+		visible = true;
 		this.t = t;
 	}
 
@@ -50,7 +52,7 @@ class BatchElement {
 		return true;
 	}
 
-	public inline function remove() {
+	public function remove() {
 		if( batch != null ) {
 			batch.delete(this);
 			batch = null;
@@ -179,6 +181,11 @@ class SpriteBatch extends Drawable {
 		var e = first;
 		var tmp = tmpBuf;
 		while( e != null ) {
+			if( !e.visible ) {
+				e = e.next();
+				continue;
+			}
+
 			var t = e.t;
 			if( hasRotationScale ) {
 				var ca = Math.cos(e.rotation), sa = Math.sin(e.rotation);

+ 5 - 0
h2d/Tile.hx

@@ -58,6 +58,11 @@ class Tile {
 		return sub(0, 0, width, height, -(width>>1), -(height>>1));
 	}
 
+	public inline function setCenterRatio(?px:Float=0.5, ?py:Float=0.5) : Void {
+		dx = -Std.int(px*width);
+		dy = -Std.int(py*height);
+	}
+
 	public function flipX() {
 		var tmp = u; u = u2; u2 = tmp;
 		dx = -dx - width;

+ 5 - 0
h2d/TileGroup.hx

@@ -335,6 +335,11 @@ class TileGroup extends Drawable {
 		content.clear();
 	}
 
+	public function invalidate() {
+		if( content.buffer!=null )
+			content.buffer.dispose();
+	}
+
 	/**
 		Returns the number of tiles added to the group
 	**/

+ 26 - 0
hxd/Key.hx

@@ -44,6 +44,32 @@ class Key {
 	public static inline var NUMPAD_9	= 105;
 
 	public static inline var A			= 65;
+	public static inline var B			= 66;
+	public static inline var C			= 67;
+	public static inline var D			= 68;
+	public static inline var E			= 69;
+	public static inline var F			= 70;
+	public static inline var G			= 71;
+	public static inline var H			= 72;
+	public static inline var I			= 73;
+	public static inline var J			= 74;
+	public static inline var K			= 75;
+	public static inline var L			= 76;
+	public static inline var M			= 77;
+	public static inline var N			= 78;
+	public static inline var O			= 79;
+	public static inline var P			= 80;
+	public static inline var Q			= 81;
+	public static inline var R			= 82;
+	public static inline var S			= 83;
+	public static inline var T			= 84;
+	public static inline var U			= 85;
+	public static inline var V			= 86;
+	public static inline var W			= 87;
+	public static inline var X			= 88;
+	public static inline var Y			= 89;
+	public static inline var Z			= 90;
+
 	public static inline var F1			= 112;
 	public static inline var F2			= 113;
 	public static inline var F3			= 114;

+ 4 - 0
hxd/res/Any.hx

@@ -67,6 +67,10 @@ class Any extends Resource {
 		return loader.loadTiledMap(entry.path);
 	}
 
+	public function toAtlas() {
+		return loader.loadAtlas(entry.path);
+	}
+
 	public inline function iterator() {
 		return new hxd.impl.ArrayIterator([for( f in entry ) new Any(loader,f)]);
 	}

+ 1 - 1
hxd/res/Sound.hx

@@ -46,7 +46,7 @@ class Sound extends Resource {
 		}
 	}
 
-	public function play( loop = false, volume = 1. ) {
+	public function play( ?loop = false, volume = 1. ) {
 		lastPlay = haxe.Timer.stamp();
 		return channel = getWorker().play(this, loop, volume);
 	}