浏览代码

Merge pull request #162 from motion-twin/mt_changes

[MotionTwin] Deepnight changes
Nicolas Cannasse 9 年之前
父节点
当前提交
e50763b12f
共有 3 个文件被更改,包括 33 次插入18 次删除
  1. 4 0
      h2d/Console.hx
  2. 5 0
      h2d/Sprite.hx
  3. 24 18
      h2d/SpriteBatch.hx

+ 4 - 0
h2d/Console.hx

@@ -49,6 +49,10 @@ class Console extends h2d.Sprite {
 		commands = new Map();
 		commands = new Map();
 		aliases = new Map();
 		aliases = new Map();
 		addCommand("help", "Show help", [ { name : "command", t : AString, opt : true } ], showHelp);
 		addCommand("help", "Show help", [ { name : "command", t : AString, opt : true } ], showHelp);
+		addCommand("cls", "Clear console", [], function() {
+			logs = [];
+			logTxt.text = "";
+		});
 		addAlias("?", "help");
 		addAlias("?", "help");
 	}
 	}
 
 

+ 5 - 0
h2d/Sprite.hx

@@ -272,6 +272,11 @@ class Sprite {
 		}
 		}
 	}
 	}
 
 
+	public function removeChildren() {
+		while( numChildren>0 )
+			removeChild( getChildAt(0) );
+	}
+
 	// shortcut for parent.removeChild
 	// shortcut for parent.removeChild
 	public inline function remove() {
 	public inline function remove() {
 		if( this != null && parent != null ) parent.removeChild(this);
 		if( this != null && parent != null ) parent.removeChild(this);

+ 24 - 18
h2d/SpriteBatch.hx

@@ -19,7 +19,9 @@ private class ElementsIterator {
 class BatchElement {
 class BatchElement {
 	public var x : Float;
 	public var x : Float;
 	public var y : Float;
 	public var y : Float;
-	public var scale : Float;
+	public var scale(never,set) : Float;
+	public var scaleX : Float;
+	public var scaleY : Float;
 	public var rotation : Float;
 	public var rotation : Float;
 	public var r : Float;
 	public var r : Float;
 	public var g : Float;
 	public var g : Float;
@@ -35,11 +37,15 @@ class BatchElement {
 
 
 	public function new(t) {
 	public function new(t) {
 		x = 0; y = 0; r = 1; g = 1; b = 1; a = 1;
 		x = 0; y = 0; r = 1; g = 1; b = 1; a = 1;
-		rotation = 0; scale = 1;
+		rotation = 0; scaleX = scaleY = 1;
 		visible = true;
 		visible = true;
 		this.t = t;
 		this.t = t;
 	}
 	}
 
 
+	inline function set_scale(v) {
+		return scaleX = scaleY = v;
+	}
+
 	inline function get_alpha() {
 	inline function get_alpha() {
 		return a;
 		return a;
 	}
 	}
@@ -149,23 +155,23 @@ class SpriteBatch extends Drawable {
 				var px = t.dx, py = t.dy;
 				var px = t.dx, py = t.dy;
 				var x, y;
 				var x, y;
 
 
-				x = (px * ca - py * sa) * e.scale + e.x;
-				y = (py * ca + px * sa) * e.scale + e.y;
+				x = (px * ca - py * sa) * e.scaleX + e.x;
+				y = (py * ca + px * sa) * e.scaleY + e.y;
 				addBounds(relativeTo, out, x, y, 1e-10, 1e-10);
 				addBounds(relativeTo, out, x, y, 1e-10, 1e-10);
 
 
 				var px = t.dx + hx, py = t.dy;
 				var px = t.dx + hx, py = t.dy;
-				x = (px * ca - py * sa) * e.scale + e.x;
-				y = (py * ca + px * sa) * e.scale + e.y;
+				x = (px * ca - py * sa) * e.scaleX + e.x;
+				y = (py * ca + px * sa) * e.scaleY + e.y;
 				addBounds(relativeTo, out, x, y, 1e-10, 1e-10);
 				addBounds(relativeTo, out, x, y, 1e-10, 1e-10);
 
 
 				var px = t.dx, py = t.dy + hy;
 				var px = t.dx, py = t.dy + hy;
-				x = (px * ca - py * sa) * e.scale + e.x;
-				y = (py * ca + px * sa) * e.scale + e.y;
+				x = (px * ca - py * sa) * e.scaleX + e.x;
+				y = (py * ca + px * sa) * e.scaleY + e.y;
 				addBounds(relativeTo, out, x, y, 1e-10, 1e-10);
 				addBounds(relativeTo, out, x, y, 1e-10, 1e-10);
 
 
 				var px = t.dx + hx, py = t.dy + hy;
 				var px = t.dx + hx, py = t.dy + hy;
-				x = (px * ca - py * sa) * e.scale + e.x;
-				y = (py * ca + px * sa) * e.scale + e.y;
+				x = (px * ca - py * sa) * e.scaleX + e.x;
+				y = (py * ca + px * sa) * e.scaleY + e.y;
 				addBounds(relativeTo, out, x, y, 1e-10, 1e-10);
 				addBounds(relativeTo, out, x, y, 1e-10, 1e-10);
 			} else
 			} else
 				addBounds(relativeTo, out, e.x + tile.dx, e.y + tile.dy, tile.width, tile.height);
 				addBounds(relativeTo, out, e.x + tile.dx, e.y + tile.dy, tile.width, tile.height);
@@ -191,8 +197,8 @@ class SpriteBatch extends Drawable {
 				var ca = Math.cos(e.rotation), sa = Math.sin(e.rotation);
 				var ca = Math.cos(e.rotation), sa = Math.sin(e.rotation);
 				var hx = t.width, hy = t.height;
 				var hx = t.width, hy = t.height;
 				var px = t.dx, py = t.dy;
 				var px = t.dx, py = t.dy;
-				tmp[pos++] = (px * ca - py * sa) * e.scale + e.x;
-				tmp[pos++] = (py * ca + px * sa) * e.scale + e.y;
+				tmp[pos++] = (px * ca - py * sa) * e.scaleX + e.x;
+				tmp[pos++] = (py * ca + px * sa) * e.scaleY + e.y;
 				tmp[pos++] = t.u;
 				tmp[pos++] = t.u;
 				tmp[pos++] = t.v;
 				tmp[pos++] = t.v;
 				tmp[pos++] = e.r;
 				tmp[pos++] = e.r;
@@ -200,8 +206,8 @@ class SpriteBatch extends Drawable {
 				tmp[pos++] = e.b;
 				tmp[pos++] = e.b;
 				tmp[pos++] = e.a;
 				tmp[pos++] = e.a;
 				var px = t.dx + hx, py = t.dy;
 				var px = t.dx + hx, py = t.dy;
-				tmp[pos++] = (px * ca - py * sa) * e.scale + e.x;
-				tmp[pos++] = (py * ca + px * sa) * e.scale + e.y;
+				tmp[pos++] = (px * ca - py * sa) * e.scaleX + e.x;
+				tmp[pos++] = (py * ca + px * sa) * e.scaleY + e.y;
 				tmp[pos++] = t.u2;
 				tmp[pos++] = t.u2;
 				tmp[pos++] = t.v;
 				tmp[pos++] = t.v;
 				tmp[pos++] = e.r;
 				tmp[pos++] = e.r;
@@ -209,8 +215,8 @@ class SpriteBatch extends Drawable {
 				tmp[pos++] = e.b;
 				tmp[pos++] = e.b;
 				tmp[pos++] = e.a;
 				tmp[pos++] = e.a;
 				var px = t.dx, py = t.dy + hy;
 				var px = t.dx, py = t.dy + hy;
-				tmp[pos++] = (px * ca - py * sa) * e.scale + e.x;
-				tmp[pos++] = (py * ca + px * sa) * e.scale + e.y;
+				tmp[pos++] = (px * ca - py * sa) * e.scaleX + e.x;
+				tmp[pos++] = (py * ca + px * sa) * e.scaleY + e.y;
 				tmp[pos++] = t.u;
 				tmp[pos++] = t.u;
 				tmp[pos++] = t.v2;
 				tmp[pos++] = t.v2;
 				tmp[pos++] = e.r;
 				tmp[pos++] = e.r;
@@ -218,8 +224,8 @@ class SpriteBatch extends Drawable {
 				tmp[pos++] = e.b;
 				tmp[pos++] = e.b;
 				tmp[pos++] = e.a;
 				tmp[pos++] = e.a;
 				var px = t.dx + hx, py = t.dy + hy;
 				var px = t.dx + hx, py = t.dy + hy;
-				tmp[pos++] = (px * ca - py * sa) * e.scale + e.x;
-				tmp[pos++] = (py * ca + px * sa) * e.scale + e.y;
+				tmp[pos++] = (px * ca - py * sa) * e.scaleX + e.x;
+				tmp[pos++] = (py * ca + px * sa) * e.scaleY + e.y;
 				tmp[pos++] = t.u2;
 				tmp[pos++] = t.u2;
 				tmp[pos++] = t.v2;
 				tmp[pos++] = t.v2;
 				tmp[pos++] = e.r;
 				tmp[pos++] = e.r;