2
0
Эх сурвалжийг харах

Interactive background accurate to width/height
More subpixel-enabled functions to Tile.

Yanrishatum 6 жил өмнө
parent
commit
b52e204dad
2 өөрчлөгдсөн 8 нэмэгдсэн , 8 устгасан
  1. 2 2
      h2d/Interactive.hx
  2. 6 6
      h2d/Tile.hx

+ 2 - 2
h2d/Interactive.hx

@@ -64,12 +64,12 @@ class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
 	}
 
 	override function draw( ctx : RenderContext ) {
-		if( backgroundColor != null ) emitTile(ctx, h2d.Tile.fromColor(backgroundColor, Std.int(width), Std.int(height), (backgroundColor>>>24)/255 ));
+		if( backgroundColor != null ) emitTile(ctx, h2d.Tile.fromColor(backgroundColor, width, height, (backgroundColor>>>24)/255 ));
 	}
 
 	override function getBoundsRec( relativeTo, out, forSize ) {
 		super.getBoundsRec(relativeTo, out, forSize);
-		if( backgroundColor != null || forSize ) addBounds(relativeTo, out, 0, 0, Std.int(width), Std.int(height));
+		if( backgroundColor != null || forSize ) addBounds(relativeTo, out, 0, 0, width, height);
 	}
 
 	override function onParentChanged() {

+ 6 - 6
h2d/Tile.hx

@@ -128,18 +128,18 @@ class Tile {
 	/**
 		Split horizontaly or verticaly the number of given frames
 	**/
-	public function split( frames : Int = 0, vertical = false ) : Array<Tile> {
+	public function split( frames : Int = 0, vertical = false, subpixel = false ) : Array<Tile> {
 		var tl = [];
 		if( vertical ) {
 			if( frames == 0 )
 				frames = Std.int(height / width);
-			var stride = Std.int(height / frames);
+			var stride = subpixel ? height / frames : Std.int(height / frames);
 			for( i in 0...frames )
 				tl.push(sub(0, i * stride, width, stride));
 		} else {
 			if( frames == 0 )
 				frames = Std.int(width / height);
-			var stride = Std.int(width / frames);
+			var stride = subpixel ? width / frames : Std.int(width / frames);
 			for( i in 0...frames )
 				tl.push(sub(i * stride, 0, stride, height));
 		}
@@ -150,14 +150,14 @@ class Tile {
 		Split the tile into a list of tiles of Size x Size pixels.
 		Unlike grid which is X/Y ordered, gridFlatten returns a single dimensional array ordered in Y/X.
 	**/
-	public function gridFlatten( size : Int, dx = 0., dy = 0. ) : Array<Tile> {
+	public function gridFlatten( size : Float, dx = 0., dy = 0. ) : Array<Tile> {
 		return [for( y in 0...Std.int(height / size) ) for( x in 0...Std.int(width / size) ) sub(x * size, y * size, size, size, dx, dy)];
 	}
 
 	/**
 		Split the tile into a list of tiles of Size x Size pixels.
 	**/
-	public function grid( size : Int, dx = 0., dy = 0. ) : Array<Array<Tile>> {
+	public function grid( size : Float, dx = 0., dy = 0. ) : Array<Array<Tile>> {
 		return [for( x in 0...Std.int(width / size) ) [for( y in 0...Std.int(height / size) ) sub(x * size, y * size, size, size, dx, dy)]];
 	}
 
@@ -182,7 +182,7 @@ class Tile {
 	}
 
 
-	public static function fromColor( color : Int, ?width = 1, ?height = 1, ?alpha = 1., ?allocPos : h3d.impl.AllocPos ) : Tile {
+	public static function fromColor( color : Int, ?width = 1., ?height = 1., ?alpha = 1., ?allocPos : h3d.impl.AllocPos ) : Tile {
 		var t = new Tile(h3d.mat.Texture.fromColor(color,alpha,allocPos),0,0,1,1);
 		// scale to size
 		t.width = width;