Explorar o código

[haxe] Fix binary asset loading, make Skeleton.getBounds() easier to use.

Mario Zechner hai 1 ano
pai
achega
806ec03e0d

+ 0 - 7
spine-haxe/.vscode/launch.json

@@ -4,13 +4,6 @@
   // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
   // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
   "version": "0.2.0",
   "version": "0.2.0",
   "configurations": [
   "configurations": [
-    {
-      "name": "web",
-      "request": "launch",
-      "type": "chrome",
-      "url": "http://localhost:3000",
-      "webRoot": "${workspaceFolder}"
-    },
     {
     {
       "name": "lime",
       "name": "lime",
       "type": "lime",
       "type": "lime",

+ 4 - 5
spine-haxe/example/src/BasicExample.hx

@@ -1,10 +1,7 @@
-import openfl.utils.Assets;
-import spine.SkeletonBinary;
+import openfl.geom.Rectangle;
 import spine.SkeletonData;
 import spine.SkeletonData;
-import spine.SkeletonJson;
 import spine.animation.AnimationStateData;
 import spine.animation.AnimationStateData;
 import spine.atlas.TextureAtlas;
 import spine.atlas.TextureAtlas;
-import spine.attachments.AtlasAttachmentLoader;
 import spine.starling.SkeletonSprite;
 import spine.starling.SkeletonSprite;
 import starling.core.Starling;
 import starling.core.Starling;
 
 
@@ -18,8 +15,10 @@ class BasicExample extends Scene {
 		animationStateData.defaultMix = 0.25;
 		animationStateData.defaultMix = 0.25;
 
 
 		var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
 		var skeletonSprite = new SkeletonSprite(skeletondata, animationStateData);
+		var bounds = skeletonSprite.skeleton.getBounds();
+		skeletonSprite.scale = Starling.current.stage.stageWidth / bounds.width * 0.5;
 		skeletonSprite.x = Starling.current.stage.stageWidth / 2;
 		skeletonSprite.x = Starling.current.stage.stageWidth / 2;
-		skeletonSprite.y = Starling.current.stage.stageHeight * 0.5;
+		skeletonSprite.y = Starling.current.stage.stageHeight * 0.9;
 
 
 		skeletonSprite.state.setAnimationByName(0, "walk", true);
 		skeletonSprite.state.setAnimationByName(0, "walk", true);
 
 

+ 1 - 0
spine-haxe/project.xml

@@ -11,5 +11,6 @@
 
 
 	<source path="example/src" />
 	<source path="example/src" />
 	<assets path="example/assets" rename="assets" />
 	<assets path="example/assets" rename="assets" />
+	<assets path="example/assets" include="*.skel" rename="assets" type="binary" />
 
 
 </project>
 </project>

+ 1 - 1
spine-haxe/spine-haxe/spine/BinaryInput.hx

@@ -76,7 +76,7 @@ class BinaryInput {
 					chars += String.fromCharCode(((b & 0x0F) << 12 | (readByte() & 0x3F) << 6 | readByte() & 0x3F));
 					chars += String.fromCharCode(((b & 0x0F) << 12 | (readByte() & 0x3F) << 6 | readByte() & 0x3F));
 					i += 3;
 					i += 3;
 				default:
 				default:
-					chars += String.fromCharCode(b);
+					chars += String.fromCharCode(b & 0xff);
 					i++;
 					i++;
 			}
 			}
 		}
 		}

+ 14 - 13
spine-haxe/spine-haxe/spine/Skeleton.hx

@@ -1,5 +1,6 @@
 package spine;
 package spine;
 
 
+import openfl.geom.Rectangle;
 import openfl.errors.ArgumentError;
 import openfl.errors.ArgumentError;
 import openfl.utils.Dictionary;
 import openfl.utils.Dictionary;
 import openfl.Vector;
 import openfl.Vector;
@@ -561,11 +562,10 @@ class Skeleton {
 		return _data.name != null ? _data.name : "Skeleton?";
 		return _data.name != null ? _data.name : "Skeleton?";
 	}
 	}
 
 
-	public function getBounds(offset:Vector<Float>, size:Vector<Float>, temp:Vector<Float>):Void {
-		if (offset == null)
-			throw new ArgumentError("offset cannot be null.");
-		if (size == null)
-			throw new ArgumentError("size cannot be null.");
+	private var _tempVertices = new Vector<Float>();
+	private var _bounds = new Rectangle();
+
+	public function getBounds():Rectangle {
 		var minX:Float = Math.POSITIVE_INFINITY;
 		var minX:Float = Math.POSITIVE_INFINITY;
 		var minY:Float = Math.POSITIVE_INFINITY;
 		var minY:Float = Math.POSITIVE_INFINITY;
 		var maxX:Float = Math.NEGATIVE_INFINITY;
 		var maxX:Float = Math.NEGATIVE_INFINITY;
@@ -576,14 +576,14 @@ class Skeleton {
 			var attachment:Attachment = slot.attachment;
 			var attachment:Attachment = slot.attachment;
 			if (Std.isOfType(attachment, RegionAttachment)) {
 			if (Std.isOfType(attachment, RegionAttachment)) {
 				verticesLength = 8;
 				verticesLength = 8;
-				temp.length = verticesLength;
-				vertices = temp;
+				_tempVertices.length = verticesLength;
+				vertices = _tempVertices;
 				cast(attachment, RegionAttachment).computeWorldVertices(slot, vertices, 0, 2);
 				cast(attachment, RegionAttachment).computeWorldVertices(slot, vertices, 0, 2);
 			} else if (Std.isOfType(attachment, MeshAttachment)) {
 			} else if (Std.isOfType(attachment, MeshAttachment)) {
 				var mesh:MeshAttachment = cast(attachment, MeshAttachment);
 				var mesh:MeshAttachment = cast(attachment, MeshAttachment);
 				verticesLength = mesh.worldVerticesLength;
 				verticesLength = mesh.worldVerticesLength;
-				temp.length = verticesLength;
-				vertices = temp;
+				_tempVertices.length = verticesLength;
+				vertices = _tempVertices;
 				mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
 				mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
 			}
 			}
 			if (vertices != null) {
 			if (vertices != null) {
@@ -599,9 +599,10 @@ class Skeleton {
 				}
 				}
 			}
 			}
 		}
 		}
-		offset[0] = minX;
-		offset[1] = minY;
-		size[0] = maxX - minX;
-		size[1] = maxY - minY;
+		_bounds.x = minX;
+		_bounds.y = minY;
+		_bounds.width = maxX - minX;
+		_bounds.height = maxY - minY;
+		return _bounds;
 	}
 	}
 }
 }