Browse Source

fixed Sprite->Object

Nicolas Cannasse 7 years ago
parent
commit
65cc499f00
6 changed files with 46 additions and 69 deletions
  1. 13 35
      samples/Base2D.hx
  2. 18 18
      samples/Filters.hx
  3. 4 4
      samples/HtmlText.hx
  4. 5 6
      samples/Mask.hx
  5. 2 2
      samples/Pad.hx
  6. 4 4
      samples/Text.hx

+ 13 - 35
samples/Base2D.hx

@@ -1,13 +1,13 @@
 class Base2D extends hxd.App {
 
-	var spr : h2d.Sprite;
+	var obj : h2d.Object;
 	var tf : h2d.Text;
 
 	override function init() {
-		// creates a new sprite and put it at the center of the sceen
-		spr = new h2d.Sprite(s2d);
-		spr.x = Std.int(s2d.width / 2);
-		spr.y = Std.int(s2d.height / 2);
+		// creates a new object and put it at the center of the sceen
+		obj = new h2d.Object(s2d);
+		obj.x = Std.int(s2d.width / 2);
+		obj.y = Std.int(s2d.height / 2);
 
 		// load the haxe logo png into a tile
 		var tile = hxd.Res.hxlogo.toTile();
@@ -16,8 +16,8 @@ class Base2D extends hxd.App {
 		tile = tile.center();
 
 		for( i in 0...15 ) {
-			// creates a bitmap into the sprite
-			var bmp = new h2d.Bitmap(tile, spr);
+			// creates a bitmap into the object
+			var bmp = new h2d.Bitmap(tile, obj);
 
 			// move its position
 			bmp.x = Math.cos(i * Math.PI / 8) * 100;
@@ -30,28 +30,6 @@ class Base2D extends hxd.App {
 			bmp.blendMode = Add;
 		}
 
-		#if (lime || !(cpp || hl))
-		// load a true type font, can be not very high quality
-		var font = hxd.Res.trueTypeFont.build(64);
-
-		// creates a text display with the given font
-		tf = new h2d.Text(font, s2d);
-
-		// set the text color
-		tf.textColor = 0xFFFFFF;
-
-		// adds a red shadow
-		tf.dropShadow = { dx : 3, dy : 3, color : 0xFF0000, alpha : 0.8 };
-
-		// set the text color
-		tf.text = "Héllò h2d !";
-
-		// set the text position
-		tf.x = 20;
-		tf.y = s2d.height - 80;
-
-		#end
-
 		// load a bitmap font Resource
 		var font = hxd.Res.customFont.toFont();
 
@@ -69,19 +47,19 @@ class Base2D extends hxd.App {
 	// if we the window has been resized
 	override function onResize() {
 
-		if( spr == null ) return;
+		if( obj == null ) return;
 
-		// center our sprite
-		spr.x = Std.int(s2d.width / 2);
-		spr.y = Std.int(s2d.height / 2);
+		// center our object
+		obj.x = Std.int(s2d.width / 2);
+		obj.y = Std.int(s2d.height / 2);
 
 		// move our text up/down accordingly
 		if( tf != null ) tf.y = s2d.height - 80;
 	}
 
 	override function update(dt:Float) {
-		// rotate our sprite every frame
-		if( spr != null ) spr.rotation += 0.01 * dt;
+		// rotate our object every frame
+		if( obj != null ) obj.rotation += 0.01 * dt;
 	}
 
 	static function main() {

+ 18 - 18
samples/Filters.hx

@@ -2,7 +2,7 @@ import hxd.Key in K;
 
 class Filters extends hxd.App {
 
-	var spr : h2d.Sprite;
+	var obj : h2d.Object;
 	var bmp : h2d.Bitmap;
 	var mask : h2d.Graphics;
 	var disp : h2d.Tile;
@@ -16,11 +16,11 @@ class Filters extends hxd.App {
 		mask.x = s2d.width*0.5-20;
 		mask.y = s2d.height*0.5-50;
 
-		spr = new h2d.Sprite(s2d);
-		spr.x = s2d.width * 0.5;
-		spr.y = s2d.height * 0.5;
+		obj = new h2d.Object(s2d);
+		obj.x = s2d.width * 0.5;
+		obj.y = s2d.height * 0.5;
 
-		bmp = new h2d.Bitmap(hxd.Res.hxlogo.toTile(), spr);
+		bmp = new h2d.Bitmap(hxd.Res.hxlogo.toTile(), obj);
 		bmp.colorKey = 0xFFFFFF;
 
 		disp = hxd.Res.normalmap.toTile();
@@ -36,14 +36,14 @@ class Filters extends hxd.App {
 			if( K.isPressed(K.NUMBER_0 + i) || K.isPressed(K.NUMPAD_0+i) )
 				setFilters(i);
 		if( K.isPressed(K.NUMPAD_ADD) ) {
-			spr.scale(1.25);
+			obj.scale(1.25);
 			bmp.scale(1 / 1.25);
 		}
 		if( K.isPressed(K.NUMPAD_SUB) ) {
-			spr.scale(1 / 1.25);
+			obj.scale(1 / 1.25);
 			bmp.scale(1.25);
-			if( spr.scaleX < 1 ) {
-				spr.setScale(1);
+			if( obj.scaleX < 1 ) {
+				obj.setScale(1);
 				bmp.setScale(1);
 			}
 		}
@@ -55,32 +55,32 @@ class Filters extends hxd.App {
 	function setFilters(i) {
 		switch( i ) {
 		case 0:
-			spr.filter = null;
+			obj.filter = null;
 		case 1:
-			spr.filter = new h2d.filter.Blur(5);
+			obj.filter = new h2d.filter.Blur(5);
 		case 2:
-			spr.filter = new h2d.filter.Glow(0xFFFFFF, 100, 5);
+			obj.filter = new h2d.filter.Glow(0xFFFFFF, 100, 5);
 		case 3:
-			spr.filter = new h2d.filter.DropShadow(8,Math.PI/4);
+			obj.filter = new h2d.filter.DropShadow(8,Math.PI/4);
 		case 4:
-			spr.filter = new h2d.filter.Displacement(disp,4,4);
+			obj.filter = new h2d.filter.Displacement(disp,4,4);
 		case 5:
 			var g = new h2d.filter.Glow(0xFFFFFF, 100, 2);
 			g.knockout = true;
-			spr.filter = g;
+			obj.filter = g;
 		case 6:
 			var g = new h2d.filter.Glow(0xFFA500, 50, 2);
 			g.knockout = true;
-			spr.filter = new h2d.filter.Group([g, new h2d.filter.Displacement(disp, 3, 3), new h2d.filter.Blur(3), new h2d.filter.DropShadow(8, Math.PI / 4)]);
+			obj.filter = new h2d.filter.Group([g, new h2d.filter.Displacement(disp, 3, 3), new h2d.filter.Blur(3), new h2d.filter.DropShadow(8, Math.PI / 4)]);
 		case 7:
 			var m = new h3d.Matrix();
 			m.identity();
 			m.colorContrast(0.5);
 			m.colorHue(Math.PI / 4);
 			m.colorSaturate(-0.5);
-			spr.filter = new h2d.filter.ColorMatrix(m);
+			obj.filter = new h2d.filter.ColorMatrix(m);
 		case 8:
-			spr.filter = new h2d.filter.Mask(mask);
+			obj.filter = new h2d.filter.Mask(mask);
 		}
 	}
 

+ 4 - 4
samples/HtmlText.hx

@@ -2,10 +2,10 @@ import h2d.Drawable;
 import h2d.Flow;
 import h2d.Font;
 import h2d.Graphics;
-import h2d.Sprite;
+import h2d.Object;
 import h2d.Text.Align;
 
-class HtmlTextWidget extends Sprite
+class HtmlTextWidget extends Object
 {
 	public var align: Align;
 	public var textField: h2d.HtmlText;
@@ -106,7 +106,7 @@ class HtmlText extends hxd.App {
 		}
 		
 		// Flows
-		function createText(parent:Sprite, str : String, align:Align) {
+		function createText(parent:Object, str : String, align:Align) {
 			var tf = new h2d.HtmlText(font, parent);
 			tf.textColor = 0xffffff;
 			tf.textAlign = align;
@@ -115,7 +115,7 @@ class HtmlText extends hxd.App {
 			return tf;
 		}
 
-		function createFlow(parent:Sprite) {
+		function createFlow(parent:Object) {
 			var flow = new Flow(parent);
 			flow.debug = true;
 			flow.horizontalSpacing = 5;

+ 5 - 6
samples/Mask.hx

@@ -1,17 +1,16 @@
 class Mask extends hxd.App {
 
-	var spr : h2d.Sprite;
-	var spr2 : h2d.Sprite;
+	var obj : h2d.Object;
 	var time : Float = 0.;
 
 	override function init() {
 		var mask = new h2d.Mask(160, 160, s2d);
 		mask.x = 200;
 		mask.y = 150;
-		spr = new h2d.Sprite(mask);
-		spr.x = spr.y = 80;
+		obj = new h2d.Object(mask);
+		obj.x = obj.y = 80;
 		for( i in 0...10 ) {
-			var b = new h2d.Bitmap(hxd.Res.hxlogo.toTile(), spr);
+			var b = new h2d.Bitmap(hxd.Res.hxlogo.toTile(), obj);
 			b.scale(0.4);
 			b.x = Std.random(200) - 100;
 			b.y = Std.random(200) - 100;
@@ -20,7 +19,7 @@ class Mask extends hxd.App {
 
 	override function update(dt:Float) {
 		time += dt/60;
-		spr.rotation += 0.01 * dt;
+		obj.rotation += 0.01 * dt;
 	}
 
 	static function main() {

+ 2 - 2
samples/Pad.hx

@@ -48,7 +48,7 @@ class Pad extends hxd.App {
 
 }
 
-class PadUI extends h2d.Sprite {
+class PadUI extends h2d.Object {
 
 	var tfName : h2d.Text;
 
@@ -64,7 +64,7 @@ class PadUI extends h2d.Sprite {
 
 	var pad : hxd.Pad;
 
-	public function new( p : hxd.Pad, parent : h2d.Sprite ){
+	public function new( p : hxd.Pad, parent : h2d.Object ){
 		super( parent );
 
 		pad = p;

+ 4 - 4
samples/Text.hx

@@ -2,10 +2,10 @@ import h2d.Drawable;
 import h2d.Flow;
 import h2d.Font;
 import h2d.Graphics;
-import h2d.Sprite;
+import h2d.Object;
 import h2d.Text.Align;
 
-class TextWidget extends Sprite
+class TextWidget extends Object
 {
 	public var align: Align;
 	public var textField: h2d.Text;
@@ -105,7 +105,7 @@ class Text extends hxd.App {
 		}
 
 		// Flows
-		function createText(parent:Sprite, str : String, align:Align) {
+		function createText(parent:Object, str : String, align:Align) {
 			var tf = new h2d.Text(font, parent);
 			tf.textColor = 0xffffff;
 			tf.textAlign = align;
@@ -114,7 +114,7 @@ class Text extends hxd.App {
 			return tf;
 		}
 
-		function createFlow(parent:Sprite) {
+		function createFlow(parent:Object) {
 			var flow = new Flow(parent);
 			flow.debug = true;
 			flow.horizontalSpacing = 5;