mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[haxe] Fix binary asset loading, make Skeleton.getBounds() easier to use.
This commit is contained in:
parent
74615a5177
commit
806ec03e0d
7
spine-haxe/.vscode/launch.json
vendored
7
spine-haxe/.vscode/launch.json
vendored
@ -4,13 +4,6 @@
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "web",
|
||||
"request": "launch",
|
||||
"type": "chrome",
|
||||
"url": "http://localhost:3000",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"name": "lime",
|
||||
"type": "lime",
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
import openfl.utils.Assets;
|
||||
import spine.SkeletonBinary;
|
||||
import openfl.geom.Rectangle;
|
||||
import spine.SkeletonData;
|
||||
import spine.SkeletonJson;
|
||||
import spine.animation.AnimationStateData;
|
||||
import spine.atlas.TextureAtlas;
|
||||
import spine.attachments.AtlasAttachmentLoader;
|
||||
import spine.starling.SkeletonSprite;
|
||||
import starling.core.Starling;
|
||||
|
||||
@ -18,8 +15,10 @@ class BasicExample extends Scene {
|
||||
animationStateData.defaultMix = 0.25;
|
||||
|
||||
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.y = Starling.current.stage.stageHeight * 0.5;
|
||||
skeletonSprite.y = Starling.current.stage.stageHeight * 0.9;
|
||||
|
||||
skeletonSprite.state.setAnimationByName(0, "walk", true);
|
||||
|
||||
|
||||
@ -11,5 +11,6 @@
|
||||
|
||||
<source path="example/src" />
|
||||
<assets path="example/assets" rename="assets" />
|
||||
<assets path="example/assets" include="*.skel" rename="assets" type="binary" />
|
||||
|
||||
</project>
|
||||
@ -76,7 +76,7 @@ class BinaryInput {
|
||||
chars += String.fromCharCode(((b & 0x0F) << 12 | (readByte() & 0x3F) << 6 | readByte() & 0x3F));
|
||||
i += 3;
|
||||
default:
|
||||
chars += String.fromCharCode(b);
|
||||
chars += String.fromCharCode(b & 0xff);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package spine;
|
||||
|
||||
import openfl.geom.Rectangle;
|
||||
import openfl.errors.ArgumentError;
|
||||
import openfl.utils.Dictionary;
|
||||
import openfl.Vector;
|
||||
@ -561,11 +562,10 @@ class 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 minY:Float = Math.POSITIVE_INFINITY;
|
||||
var maxX:Float = Math.NEGATIVE_INFINITY;
|
||||
@ -576,14 +576,14 @@ class Skeleton {
|
||||
var attachment:Attachment = slot.attachment;
|
||||
if (Std.isOfType(attachment, RegionAttachment)) {
|
||||
verticesLength = 8;
|
||||
temp.length = verticesLength;
|
||||
vertices = temp;
|
||||
_tempVertices.length = verticesLength;
|
||||
vertices = _tempVertices;
|
||||
cast(attachment, RegionAttachment).computeWorldVertices(slot, vertices, 0, 2);
|
||||
} else if (Std.isOfType(attachment, MeshAttachment)) {
|
||||
var mesh:MeshAttachment = cast(attachment, MeshAttachment);
|
||||
verticesLength = mesh.worldVerticesLength;
|
||||
temp.length = verticesLength;
|
||||
vertices = temp;
|
||||
_tempVertices.length = verticesLength;
|
||||
vertices = _tempVertices;
|
||||
mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user