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

This commit is contained in:
Mario Zechner 2023-09-13 17:36:45 +02:00
parent 74615a5177
commit 806ec03e0d
5 changed files with 20 additions and 26 deletions

View File

@ -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",

View File

@ -1,10 +1,7 @@
import openfl.utils.Assets; import openfl.geom.Rectangle;
import spine.SkeletonBinary;
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);

View File

@ -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>

View File

@ -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++;
} }
} }

View File

@ -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 { private var _tempVertices = new Vector<Float>();
if (offset == null) private var _bounds = new Rectangle();
throw new ArgumentError("offset cannot be null.");
if (size == null) public function getBounds():Rectangle {
throw new ArgumentError("size cannot be null.");
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; _tempVertices.length = verticesLength;
vertices = temp; 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; _tempVertices.length = verticesLength;
vertices = temp; 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; _bounds.x = minX;
offset[1] = minY; _bounds.y = minY;
size[0] = maxX - minX; _bounds.width = maxX - minX;
size[1] = maxY - minY; _bounds.height = maxY - minY;
return _bounds;
} }
} }