Explorar o código

merged tile and tilepos, don't keep bitmapdata in memory

git-svn-id: https://svn.shirogames.com/evoland1/lib@15 9d342a87-36e0-4458-8f1b-22e0acdbfa51
ncannasse %!s(int64=13) %!d(string=hai) anos
pai
achega
14e5fefc7b
Modificáronse 11 ficheiros con 141 adicións e 171 borrados
  1. 6 6
      h2d/Bitmap.hx
  2. 5 5
      h2d/CachedBitmap.hx
  3. 21 11
      h2d/Font.hx
  4. 4 4
      h2d/Graphics.hx
  5. 2 2
      h2d/HtmlText.hx
  6. 8 8
      h2d/SpriteBatch.hx
  7. 67 67
      h2d/Tile.hx
  8. 8 8
      h2d/TileColorGroup.hx
  9. 10 8
      h2d/TileGroup.hx
  10. 0 42
      h2d/TilePos.hx
  11. 10 10
      h2d/Tools.hx

+ 6 - 6
h2d/Bitmap.hx

@@ -2,18 +2,18 @@ package h2d;
 
 class Bitmap extends Sprite {
 
-	public var data : TilePos;
+	public var tile : Tile;
 	public var color : h3d.Color;
 	public var alpha(get, set) : Float;
 	
-	public function new( ?data : TilePos, ?parent ) {
+	public function new( ?tile, ?parent ) {
 		super(parent);
 		color = new h3d.Color(1, 1, 1, 1);
-		this.data = data;
+		this.tile = tile;
 	}
 	
 	override function draw( engine : h3d.Engine ) {
-		Tools.drawTile(engine, this, data, color, blendMode);
+		Tools.drawTile(engine, this, tile, color, blendMode);
 	}
 	
 	inline function get_alpha() {
@@ -24,8 +24,8 @@ class Bitmap extends Sprite {
 		return color.a = v;
 	}
 		
-	public static function ofBitmap( bmp : flash.display.BitmapData ) {
-		return new Bitmap(Tiles.fromBitmap(bmp).get(0));
+	public static function create( bmp : flash.display.BitmapData ) {
+		return new Bitmap(Tile.fromBitmap(bmp));
 	}
 	
 }

+ 5 - 5
h2d/CachedBitmap.hx

@@ -34,7 +34,7 @@ class CachedBitmap extends Sprite {
 	var renderDone : Bool;
 	var realWidth : Int;
 	var realHeight : Int;
-	var tile : TilePos;
+	var tile : Tile;
 	
 	public function new( ?parent, width = -1, height = -1 ) {
 		super(parent);
@@ -91,8 +91,8 @@ class CachedBitmap extends Sprite {
 		}
 		Tools.setBlendMode(b.material,blendMode);
 		var tmp = TMP_VECTOR;
-		tmp.x = tile.w;
-		tmp.y = tile.h;
+		tmp.x = tile.width;
+		tmp.y = tile.height;
 		tmp.z = 1;
 		b.shader.size = tmp;
 		tmp.x = matA;
@@ -119,7 +119,7 @@ class CachedBitmap extends Sprite {
 			tmp.w = colorAdd.a;
 		}
 		b.shader.acolor = tmp;
-		b.shader.tex = tile.tiles.getTexture(engine);
+		b.shader.tex = tile.tex;
 		b.render(engine);
 	}
 	
@@ -137,7 +137,7 @@ class CachedBitmap extends Sprite {
 			while( th < realHeight ) th <<= 1;
 			tex = engine.mem.allocTargetTexture(tw, th);
 			renderDone = false;
-			tile = Tiles.fromTexture(tex).create(0, 0, realWidth, realHeight);
+			tile = new Tile(tex,0, 0, realWidth, realHeight);
 		}
 		if( !freezed || !renderDone ) {
 			var oldA = matA, oldB = matB, oldC = matC, oldD = matD, oldX = absX, oldY = absY;

+ 21 - 11
h2d/Font.hx

@@ -1,11 +1,13 @@
 package h2d;
 
-class Font extends Tiles {
+class Font extends Tile {
 
 	static var DEFAULT_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ?!,()-/'\"éèêëÉÈÊËàâäáÀÂÄÁùûüúÙÛÜÚîïíÎÏÍôóöõÔÓÖæÆœŒçÇñÑ";
+
+	public var glyphs : Array<Tile>;
 	
 	public function new( name : String, size : Int, aa = true, ?chars ) {
-		super();
+		super(null, 0, 0, 0, 0);
 		if( chars == null )
 			chars = DEFAULT_CHARS;
 		var tf = new flash.text.TextField();
@@ -25,12 +27,14 @@ class Font extends Tiles {
 			tf.antiAliasType = flash.text.AntiAliasType.ADVANCED;
 		}
 		var surf = 0;
+		var sizes = [];
 		for( i in 0...chars.length ) {
 			tf.text = chars.charAt(i);
 			var w = Math.ceil(tf.textWidth);
 			if( w == 0 ) continue;
 			var h = Math.ceil(tf.textHeight);
 			surf += (w + 1) * (h + 1);
+			sizes[i] = { w:w, h:h };
 		}
 		var side = Math.ceil( Math.sqrt(surf) );
 		var width = 1;
@@ -39,22 +43,23 @@ class Font extends Tiles {
 		var height = width;
 		while( width * height >> 1 > surf )
 			height >>= 1;
-		var letters;
+		var all, bmp;
 		do {
 			bmp = new flash.display.BitmapData(width, height, true, 0);
-			letters = [];
+			glyphs = [];
+			all = [];
 			var m = new flash.geom.Matrix();
 			var x = 0, y = 0, lineH = 0;
 			for( i in 0...chars.length ) {
-				tf.text = chars.charAt(i);
-				var w = Math.ceil(tf.textWidth);
-				if( w == 0 ) continue;
-				var h = Math.ceil(tf.textHeight);
+				var size = sizes[i];
+				if( size == null ) continue;
+				var w = size.w;
+				var h = size.h;
 				if( x + w > width ) {
 					x = 0;
 					y += lineH + 1;
 				}
-				// no space
+				// no space, resize
 				if( y + h > height ) {
 					bmp.dispose();
 					bmp = null;
@@ -63,14 +68,19 @@ class Font extends Tiles {
 				}
 				m.tx = x - 2;
 				m.ty = y - 2;
+				tf.text = chars.charAt(i);
 				bmp.draw(tf, m);
-				letters[chars.charCodeAt(i)] = create(x, y, w, h, 2, 2);
+				var t = sub(x, y, w, h, 2, 2);
+				all.push(t);
+				glyphs[chars.charCodeAt(i)] = t;
 				// next element
 				if( h > lineH ) lineH = h;
 				x += w + 1;
 			}
 		} while( bmp == null );
-		elements[0] = letters;
+		setTexture(Tile.fromBitmap(bmp).tex);
+		for( t in all )
+			t.setTexture(tex);
 	}
 	
 }

+ 4 - 4
h2d/Graphics.hx

@@ -33,7 +33,7 @@ class GraphicsContext {
 
 class Graphics extends Sprite {
 
-	var tile : TilePos;
+	var tile : Tile;
 	var ctx : GraphicsContext;
 		
 	public function beginDraw() {
@@ -42,7 +42,7 @@ class Graphics extends Sprite {
 	
 	override function onDelete() {
 		if( tile != null ) {
-			tile.tiles.dispose();
+			tile.tex.dispose();
 			tile = null;
 		}
 		super.onDelete();
@@ -50,8 +50,8 @@ class Graphics extends Sprite {
 	
 	public function endDraw() {
 		if( ctx == null ) return;
-		if( tile != null ) tile.tiles.dispose();
-		tile = Tiles.fromSprites([ctx.mc]).get(0);
+		if( tile != null ) tile.tex.dispose();
+		tile = Tile.fromSprites([ctx.mc])[0];
 	}
 	
 	override function draw(engine) {

+ 2 - 2
h2d/HtmlText.hx

@@ -20,7 +20,7 @@ class HtmlText extends Sprite {
 		this.htmlText = t;
 		glyphs.reset();
 		glyphs.setColor(textColor);
-		var letters = font.elements[0];
+		var letters = font.glyphs;
 		var x = 0, y = 0;
 		function loop( e : Xml ) {
 			if( e.nodeType == Xml.Element ) {
@@ -49,7 +49,7 @@ class HtmlText extends Sprite {
 					var e = letters[cc];
 					if( e == null ) continue;
 					glyphs.add(x, y, e);
-					x += e.w + 1;
+					x += e.width + 1;
 				}
 			}
 		}

+ 8 - 8
h2d/SpriteBatch.hx

@@ -29,7 +29,7 @@ class BatchElement {
 	public var x : Float;
 	public var y : Float;
 	public var alpha : Float;
-	public var t : TilePos;
+	public var t : Tile;
 	public var batch(default, null) : SpriteBatch;
 	
 	var prev : BatchElement;
@@ -49,7 +49,7 @@ class BatchElement {
 
 class SpriteBatch extends Sprite {
 
-	public var tiles : Tiles;
+	public var tile : Tile;
 	var first : BatchElement;
 	var last : BatchElement;
 	var tmpBuf : flash.Vector<Float>;
@@ -58,7 +58,7 @@ class SpriteBatch extends Sprite {
 	static var SHADER = null;
 	
 	public function new(t,?parent) {
-		tiles = t;
+		tile = t;
 		if( SHADER == null )
 			SHADER = new BatchShader();
 		material = new h3d.mat.Material(SHADER);
@@ -114,18 +114,18 @@ class SpriteBatch extends Sprite {
 			tmp[pos++] = t.u;
 			tmp[pos++] = t.v;
 			tmp[pos++] = e.alpha;
-			tmp[pos++] = sx + t.w + 0.1;
+			tmp[pos++] = sx + t.width + 0.1;
 			tmp[pos++] = sy;
 			tmp[pos++] = t.u2;
 			tmp[pos++] = t.v;
 			tmp[pos++] = e.alpha;
 			tmp[pos++] = sx;
-			tmp[pos++] = sy + t.h + 0.1;
+			tmp[pos++] = sy + t.height + 0.1;
 			tmp[pos++] = t.u;
 			tmp[pos++] = t.v2;
 			tmp[pos++] = e.alpha;
-			tmp[pos++] = sx + t.w + 0.1;
-			tmp[pos++] = sy + t.h + 0.1;
+			tmp[pos++] = sx + t.width + 0.1;
+			tmp[pos++] = sy + t.height + 0.1;
 			tmp[pos++] = t.u2;
 			tmp[pos++] = t.v2;
 			tmp[pos++] = e.alpha;
@@ -133,7 +133,7 @@ class SpriteBatch extends Sprite {
 		}
 		var buffer = engine.mem.allocVector(tmpBuf, 5, 4);
 		var shader = SHADER;
-		shader.tex = tiles.getTexture(engine);
+		shader.tex = tile.tex;
 		shader.mat1 = new h3d.Vector(matA, matC, absX);
 		shader.mat2 = new h3d.Vector(matB, matD, absY);
 		engine.selectMaterial(material);

+ 67 - 67
h2d/Tiles.hx → h2d/Tile.hx

@@ -1,104 +1,102 @@
 package h2d;
 
-class Tiles {
+@:allow(h2d)
+class Tile {
+	
+	static inline var EPSILON_PIXEL = 0.00001;
 	
-	var bmp : flash.display.BitmapData;
 	var tex : h3d.mat.Texture;
-	public var width(get, null) : Int;
-	public var height(get, null) : Int;
-	public var elements : Array<Array<TilePos>>;
 	
-	public function new() {
-		elements = [];
-	}
+	var u : Float;
+	var v : Float;
+	var u2 : Float;
+	var v2 : Float;
 	
-	public function create( x, y, w, h, dx = 0, dy = 0 ) {
-		return new TilePos(this, x, y, w, h, dx, dy);
-	}
+	public var dx : Int;
+	public var dy : Int;
+	public var x(default,null) : Int;
+	public var y(default,null) : Int;
+	public var width(default,null) : Int;
+	public var height(default,null) : Int;
 	
-	function get_width() {
-		return tex == null ? bmp.width : tex.width;
-	}
-
-	function get_height() {
-		return tex == null ? bmp.height : tex.height;
+	function new(tex, x, y, w, h, dx=0, dy=0) {
+		this.tex = tex;
+		this.x = x;
+		this.y = y;
+		this.width = w;
+		this.height = h;
+		this.dx = dx;
+		this.dy = dy;
+		if( tex != null ) setTexture(tex);
 	}
 	
-	public function get( id : Int ) {
-		var e = elements[0][id];
-		if( e == null )
-			throw "Invalid tile #" + id;
-		return e;
+	public function setTexture(tex) {
+		this.tex = tex;
+		this.u = x / tex.width;
+		this.v = y / tex.height;
+		this.u2 = (x + width - EPSILON_PIXEL) / tex.width;
+		this.v2 = (y + height - EPSILON_PIXEL) / tex.height;
 	}
 	
-	public function getBitmap() {
-		return bmp;
+	public function sub( x, y, w, h, dx = 0, dy = 0 ) {
+		return new Tile(tex, this.x + x, this.y + y, w, h, dx, dy);
 	}
 	
-	public function dispose() {
-		if( bmp != null ) {
-			bmp.dispose();
-			bmp = null;
-		}
-		if( tex != null ) {
-			tex.dispose();
-			tex = null;
-		}
-	}
-	
-	public function getTexture( engine : h3d.Engine ) {
-		if( tex == null ) {
-			tex = engine.mem.allocTexture(bmp.width, bmp.height);
-			tex.upload(bmp);
-		}
-		return tex;
-	}
-	
-	public static function fromBitmap( bmp : flash.display.BitmapData ) {
-		var tl = new Tiles();
+	public static function fromBitmap( bmp : flash.display.BitmapData, freeBitmap = true ) {
 		var w = 1, h = 1;
 		while( w < bmp.width )
 			w <<= 1;
 		while( h < bmp.height )
 			h <<= 1;
+		var tex = h3d.Engine.getCurrent().mem.allocTexture(w, h);
 		if( w != bmp.width || h != bmp.height ) {
 			var bmp2 = new flash.display.BitmapData(w, h, true, 0);
 			var p0 = new flash.geom.Point(0, 0);
 			bmp2.copyPixels(bmp, bmp.rect, p0, bmp, p0, true);
-			tl.bmp = bmp2;
-			bmp.dispose();
+			tex.upload(bmp2);
+			bmp2.dispose();
 		} else
-			tl.bmp = bmp;
-		tl.elements.push([new TilePos(tl, 0, 0, tl.width, tl.height)]);
-		return tl;
+			tex.upload(bmp);
+		var t = new Tile(tex, 0, 0, bmp.width, bmp.height);
+		if( freeBitmap )
+			bmp.dispose();
+		return t;
 	}
 
-	public static function autoCut( bmp : flash.display.BitmapData, size : Int ) {
+	public static function autoCut( bmp : flash.display.BitmapData, size : Int, freeBitmap = true ) {
 		var colorBG = bmp.getPixel32(bmp.width - 1, bmp.height - 1);
-		var tl = new Tiles();
-		tl.bmp = bmp;
+		var tl = new Array();
+		var w = 1, h = 1;
+		while( w < bmp.width )
+			w <<= 1;
+		while( h < bmp.height )
+			h <<= 1;
+		var tex = h3d.Engine.getCurrent().mem.allocTexture(w, h);
 		for( y in 0...Std.int(bmp.height / size) ) {
 			var a = [];
-			tl.elements[y] = a;
+			tl[y] = a;
 			for( x in 0...Std.int(bmp.width / size) ) {
 				var sz = isEmpty(bmp, x * size, y * size, size, colorBG);
 				if( sz == null )
 					break;
-				a.push(new TilePos(tl, x*size+sz.dx, y*size+sz.dy, sz.w, sz.h, sz.dx, sz.dy));
+				a.push(new Tile(tex,x*size+sz.dx, y*size+sz.dy, sz.w, sz.h, sz.dx, sz.dy));
 			}
 		}
-		return tl;
-	}
-	
-	public static function fromTexture( tex : h3d.mat.Texture ) {
-		var t = new Tiles();
-		t.tex = tex;
-		return t;
+		if( w != bmp.width || h != bmp.height ) {
+			var bmp2 = new flash.display.BitmapData(w, h, true, 0);
+			var p0 = new flash.geom.Point(0, 0);
+			bmp2.copyPixels(bmp, bmp.rect, p0, bmp, p0, true);
+			tex.upload(bmp2);
+			bmp2.dispose();
+		} else
+			tex.upload(bmp);
+		var main = new Tile(tex, 0, 0, bmp.width, bmp.height);
+		if( freeBitmap )
+			bmp.dispose();
+		return { main : main, tiles : tl };
 	}
 	
 	public static function fromSprites( sprites : Array<flash.display.Sprite> ) {
-		var tl = new Tiles();
-		tl.elements[0] = [];
 		var tmp = [];
 		var width = 0;
 		var height = 0;
@@ -118,15 +116,17 @@ class Tiles {
 		while( rh < height )
 			rh <<= 1;
 		var bmp = new flash.display.BitmapData(rw, rh, true, 0);
-		tl.bmp = bmp;
 		var m = new flash.geom.Matrix();
 		for( t in tmp ) {
 			m.tx = t.x-t.dx;
 			m.ty = -t.dy;
 			bmp.draw(t.s, m);
-			tl.elements[0].push(new TilePos(tl, t.x, 0, t.w, t.h, t.dx, t.dy));
 		}
-		return tl;
+		var main = fromBitmap(bmp);
+		var tiles = [];
+		for( t in tmp )
+			tiles.push(main.sub(t.x, 0, t.w, t.h, t.dx, t.dy));
+		return tiles;
 	}
 	
 	static function isEmpty( b : flash.display.BitmapData, px, py, size, bg : UInt ) {

+ 8 - 8
h2d/TileColorGroup.hx

@@ -41,7 +41,7 @@ private class TileLayerContent extends h3d.prim.Primitive {
 		buffer = null;
 	}
 	
-	public function add( x : Int, y : Int, r : Float, g : Float, b : Float, a : Float, t : TilePos ) {
+	public function add( x : Int, y : Int, r : Float, g : Float, b : Float, a : Float, t : Tile ) {
 		var sx = x + t.dx;
 		var sy = y + t.dy;
 		tmp[pos++] = sx;
@@ -52,7 +52,7 @@ private class TileLayerContent extends h3d.prim.Primitive {
 		tmp[pos++] = g;
 		tmp[pos++] = b;
 		tmp[pos++] = a;
-		tmp[pos++] = sx + t.w + 0.1;
+		tmp[pos++] = sx + t.width + 0.1;
 		tmp[pos++] = sy;
 		tmp[pos++] = t.u2;
 		tmp[pos++] = t.v;
@@ -61,15 +61,15 @@ private class TileLayerContent extends h3d.prim.Primitive {
 		tmp[pos++] = b;
 		tmp[pos++] = a;
 		tmp[pos++] = sx;
-		tmp[pos++] = sy + t.h + 0.1;
+		tmp[pos++] = sy + t.height + 0.1;
 		tmp[pos++] = t.u;
 		tmp[pos++] = t.v2;
 		tmp[pos++] = r;
 		tmp[pos++] = g;
 		tmp[pos++] = b;
 		tmp[pos++] = a;
-		tmp[pos++] = sx + t.w + 0.1;
-		tmp[pos++] = sy + t.h + 0.1;
+		tmp[pos++] = sx + t.width + 0.1;
+		tmp[pos++] = sy + t.height + 0.1;
 		tmp[pos++] = t.u2;
 		tmp[pos++] = t.v2;
 		tmp[pos++] = r;
@@ -98,11 +98,11 @@ class TileColorGroup extends Sprite {
 	var content : TileLayerContent;
 	var curColor : h3d.Color;
 	
-	public var tiles : Tiles;
+	public var tile : Tile;
 	
 	public function new(t,?parent) {
 		super(parent);
-		tiles = t;
+		tile = t;
 		curColor = new h3d.Color(1, 1, 1, 1);
 		content = new TileLayerContent();
 		if( SHADER == null )
@@ -146,7 +146,7 @@ class TileColorGroup extends Sprite {
 	
 	override function draw(engine:h3d.Engine) {
 		var shader = SHADER;
-		shader.tex = tiles.getTexture(engine);
+		shader.tex = tile.tex;
 		shader.mat1 = new h3d.Vector(matA, matC, absX);
 		shader.mat2 = new h3d.Vector(matB, matD, absY);
 		object.render(engine);

+ 10 - 8
h2d/TileGroup.hx

@@ -38,23 +38,25 @@ private class TileLayerContent extends h3d.prim.Primitive {
 		buffer = null;
 	}
 	
-	public function add( x : Int, y : Int, t : TilePos ) {
+	public function add( x : Int, y : Int, t : Tile ) {
 		var sx = x + t.dx;
 		var sy = y + t.dy;
+		var sx2 = sx + t.width + 0.1;
+		var sy2 = sy + t.height + 0.1;
 		tmp[pos++] = sx;
 		tmp[pos++] = sy;
 		tmp[pos++] = t.u;
 		tmp[pos++] = t.v;
-		tmp[pos++] = sx + t.w + 0.1;
+		tmp[pos++] = sx2;
 		tmp[pos++] = sy;
 		tmp[pos++] = t.u2;
 		tmp[pos++] = t.v;
 		tmp[pos++] = sx;
-		tmp[pos++] = sy + t.h + 0.1;
+		tmp[pos++] = sy2;
 		tmp[pos++] = t.u;
 		tmp[pos++] = t.v2;
-		tmp[pos++] = sx + t.w + 0.1;
-		tmp[pos++] = sy + t.h + 0.1;
+		tmp[pos++] = sx2;
+		tmp[pos++] = sy2;
 		tmp[pos++] = t.u2;
 		tmp[pos++] = t.v2;
 	}
@@ -78,11 +80,11 @@ class TileGroup extends Sprite {
 	var object : h3d.Object;
 	var content : TileLayerContent;
 	
-	public var tiles : Tiles;
+	public var tile : Tile;
 	public var color(default, null) : h3d.Color;
 	
 	public function new(t,?parent) {
-		tiles = t;
+		tile = t;
 		color = new h3d.Color(1, 1, 1, 1);
 		content = new TileLayerContent();
 		if( SHADER == null )
@@ -119,7 +121,7 @@ class TileGroup extends Sprite {
 	
 	override function draw(engine:h3d.Engine) {
 		var shader = SHADER;
-		shader.tex = tiles.getTexture(engine);
+		shader.tex = tile.tex;
 		shader.mat1 = new h3d.Vector(matA, matC, absX);
 		shader.mat2 = new h3d.Vector(matB, matD, absY);
 		shader.color = color.toVector();

+ 0 - 42
h2d/TilePos.hx

@@ -1,42 +0,0 @@
-package h2d;
-
-class TilePos {
-
-	static inline var EPSILON_PIXEL = 0.00001;
-	
-	public var tiles(default,null) : Tiles;
-	public var u : Float;
-	public var v : Float;
-	public var u2 : Float;
-	public var v2 : Float;
-	public var dx : Int;
-	public var dy : Int;
-	public var w : Int;
-	public var h : Int;
-	
-	@:allow(h2d.Tiles)
-	function new(t, x, y, w, h, dx=0, dy=0) {
-		this.tiles = t;
-		this.u = x / t.width;
-		this.v = y / t.height;
-		this.u2 = (x + w - EPSILON_PIXEL) / t.width;
-		this.v2 = (y + h - EPSILON_PIXEL) / t.height;
-		this.dx = dx;
-		this.dy = dy;
-		this.w = w;
-		this.h = h;
-	}
-	
-	public function getPosX() {
-		return Std.int(u * tiles.width);
-	}
-
-	public function getPosY() {
-		return Std.int(v * tiles.height);
-	}
-	
-	public function toString() {
-		return "TilePos(x=" + getPosX() + ",y=" + getPosY() + ",size=" + w + "x" + h + ")";
-	}
-
-}

+ 10 - 10
h2d/Tools.hx

@@ -29,7 +29,7 @@ class Tools {
 	static var TMP_VECTOR = new h3d.Vector();
 		
 	@:allow(h2d)
-	static function drawTile( engine : h3d.Engine, spr : Sprite, data : TilePos, color : h3d.Color, blendMode : BlendMode ) {
+	static function drawTile( engine : h3d.Engine, spr : Sprite, tile : Tile, color : h3d.Color, blendMode : BlendMode ) {
 		var b = BITMAP_OBJ;
 		if( b == null ) {
 			var p = new h3d.prim.Quads([
@@ -45,23 +45,23 @@ class Tools {
 		}
 		setBlendMode(b.material, blendMode);
 		var tmp = TMP_VECTOR;
-		tmp.x = data.w;
-		tmp.y = data.h;
+		tmp.x = tile.width;
+		tmp.y = tile.height;
 		tmp.z = 1;
 		b.shader.size = tmp;
 		tmp.x = spr.matA;
 		tmp.y = spr.matC;
-		tmp.z = spr.absX + data.dx * spr.matA + data.dy * spr.matC;
+		tmp.z = spr.absX + tile.dx * spr.matA + tile.dy * spr.matC;
 		b.shader.mat1 = tmp;
 		tmp.x = spr.matB;
 		tmp.y = spr.matD;
-		tmp.z = spr.absY + data.dx * spr.matB + data.dy * spr.matD;
+		tmp.z = spr.absY + tile.dx * spr.matB + tile.dy * spr.matD;
 		b.shader.mat2 = tmp;
-		tmp.x = data.u;
-		tmp.y = data.v;
+		tmp.x = tile.u;
+		tmp.y = tile.v;
 		b.shader.uvPos = tmp;
-		tmp.x = data.u2 - data.u;
-		tmp.y = data.v2 - data.v;
+		tmp.x = tile.u2 - tile.u;
+		tmp.y = tile.v2 - tile.v;
 		b.shader.uvScale = tmp;
 		if( color == null ) {
 			tmp.x = 1;
@@ -71,7 +71,7 @@ class Tools {
 			b.shader.color = tmp;
 		} else
 			b.shader.color = color.toVector();
-		b.shader.tex = data.tiles.getTexture(engine);
+		b.shader.tex = tile.tex;
 		b.render(engine);
 	}