mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[haxe] Fix texture atlas loading, sequence example.
This commit is contained in:
parent
ee502d854b
commit
9eab06f3ba
@ -51,4 +51,4 @@ As an IDE, we recommend [Visual Studio Code](https://code.visualstudio.com/) wit
|
|||||||
|
|
||||||
The extensions provide IDE features like auto-completion, debugging, and build support.
|
The extensions provide IDE features like auto-completion, debugging, and build support.
|
||||||
|
|
||||||
To debug the HTML5 build, set the Lime target in the status bar at the bottom of VS Code to `HTML5 / Debug`. Next, press `CTRL+SHIFT+B` (`CMD+SHIFT+B` on macOS) to build the project. Run the `lime` run configuration by pressing `F5`. This will start a webserver at `http://localhost:3000`. Finally, start the `web` run configuration. If you modify code, rebuild and restart the `web` configuration.
|
To debug a build, set the corresponding Lime target in the status bar at the bottom of VS Code to e.g. `HTML5 / Debug`. Run the `lime` run configuration by pressing `F5`.
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import openfl.geom.Rectangle;
|
|
||||||
import spine.SkeletonData;
|
import spine.SkeletonData;
|
||||||
import spine.animation.AnimationStateData;
|
import spine.animation.AnimationStateData;
|
||||||
import spine.atlas.TextureAtlas;
|
import spine.atlas.TextureAtlas;
|
||||||
import spine.starling.SkeletonSprite;
|
import spine.starling.SkeletonSprite;
|
||||||
import starling.core.Starling;
|
import starling.core.Starling;
|
||||||
|
import starling.events.TouchEvent;
|
||||||
|
import starling.events.TouchPhase;
|
||||||
|
|
||||||
class BasicExample extends Scene {
|
class BasicExample extends Scene {
|
||||||
var loadBinary = true;
|
var loadBinary = true;
|
||||||
@ -24,5 +25,14 @@ class BasicExample extends Scene {
|
|||||||
|
|
||||||
addChild(skeletonSprite);
|
addChild(skeletonSprite);
|
||||||
juggler.add(skeletonSprite);
|
juggler.add(skeletonSprite);
|
||||||
|
|
||||||
|
addEventListener(TouchEvent.TOUCH, onTouch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onTouch(e:TouchEvent) {
|
||||||
|
var touch = e.getTouch(this);
|
||||||
|
if (touch != null && touch.phase == TouchPhase.ENDED) {
|
||||||
|
trace("Mouse clicked");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,6 @@ class Main extends Sprite {
|
|||||||
starlingSingleton.start();
|
starlingSingleton.start();
|
||||||
Starling.current.stage.color = 0x000000;
|
Starling.current.stage.color = 0x000000;
|
||||||
|
|
||||||
SceneManager.getInstance().switchScene(new BasicExample());
|
SceneManager.getInstance().switchScene(new SequenceExample());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import starling.utils.Color;
|
||||||
|
import starling.display.Quad;
|
||||||
import starling.core.Starling;
|
import starling.core.Starling;
|
||||||
import starling.display.Sprite;
|
import starling.display.Sprite;
|
||||||
|
|
||||||
|
|||||||
42
spine-haxe/example/src/SequenceExample.hx
Normal file
42
spine-haxe/example/src/SequenceExample.hx
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import spine.SkeletonData;
|
||||||
|
import spine.animation.AnimationStateData;
|
||||||
|
import spine.atlas.TextureAtlas;
|
||||||
|
import spine.starling.SkeletonSprite;
|
||||||
|
import starling.core.Starling;
|
||||||
|
import starling.events.TouchEvent;
|
||||||
|
import starling.events.TouchPhase;
|
||||||
|
|
||||||
|
class SequenceExample extends Scene {
|
||||||
|
var loadBinary = false;
|
||||||
|
|
||||||
|
public function load():Void {
|
||||||
|
var atlas = TextureAtlas.fromAssets("assets/dragon.atlas");
|
||||||
|
var skeletondata = SkeletonData.fromAssets("assets/dragon-ess" + (loadBinary ? ".skel" : ".json"), atlas);
|
||||||
|
var animationStateData = new AnimationStateData(skeletondata);
|
||||||
|
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.9;
|
||||||
|
|
||||||
|
FIXME
|
||||||
|
sequences
|
||||||
|
are
|
||||||
|
broken
|
||||||
|
skeletonSprite.state.setAnimationByName(0, "flying", true);
|
||||||
|
|
||||||
|
addChild(skeletonSprite);
|
||||||
|
juggler.add(skeletonSprite);
|
||||||
|
|
||||||
|
addEventListener(TouchEvent.TOUCH, onTouch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onTouch(e:TouchEvent) {
|
||||||
|
var touch = e.getTouch(this);
|
||||||
|
if (touch != null && touch.phase == TouchPhase.ENDED) {
|
||||||
|
trace("Mouse clicked");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -929,7 +929,7 @@ class SkeletonJson {
|
|||||||
throw new SpineException("Slot not found: " + slotMapName);
|
throw new SpineException("Slot not found: " + slotMapName);
|
||||||
for (attachmentMapName in slotMap) {
|
for (attachmentMapName in slotMap) {
|
||||||
var attachmentMap = slotMap[attachmentMapName];
|
var attachmentMap = slotMap[attachmentMapName];
|
||||||
var attachment:VertexAttachment = cast(skin.getAttachment(slotIndex, attachmentMapName), VertexAttachment);
|
var attachment:Attachment = skin.getAttachment(slotIndex, attachmentMapName);
|
||||||
if (attachment == null)
|
if (attachment == null)
|
||||||
throw new SpineException("Timeline attachment not found: " + attachmentMapName);
|
throw new SpineException("Timeline attachment not found: " + attachmentMapName);
|
||||||
|
|
||||||
@ -940,11 +940,12 @@ class SkeletonJson {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (timelineMapName == "deform") {
|
if (timelineMapName == "deform") {
|
||||||
var weighted:Bool = attachment.bones != null;
|
var vertexAttachment = cast(attachment, VertexAttachment);
|
||||||
var vertices:Vector<Float> = attachment.vertices;
|
var weighted:Bool = vertexAttachment.bones != null;
|
||||||
|
var vertices:Vector<Float> = vertexAttachment.vertices;
|
||||||
var deformLength:Int = weighted ? Std.int(vertices.length / 3 * 2) : vertices.length;
|
var deformLength:Int = weighted ? Std.int(vertices.length / 3 * 2) : vertices.length;
|
||||||
|
|
||||||
var deformTimeline:DeformTimeline = new DeformTimeline(timelineMap.length, timelineMap.length, slotIndex, attachment);
|
var deformTimeline:DeformTimeline = new DeformTimeline(timelineMap.length, timelineMap.length, slotIndex, vertexAttachment);
|
||||||
time = getFloat(keyMap, "time");
|
time = getFloat(keyMap, "time");
|
||||||
frame = 0;
|
frame = 0;
|
||||||
bezier = 0;
|
bezier = 0;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class TextureAtlas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var textureLoader = new AssetsTextureLoader(basePath);
|
var textureLoader = new AssetsTextureLoader(basePath);
|
||||||
return new TextureAtlas(Assets.getText("assets/raptor.atlas"), textureLoader);
|
return new TextureAtlas(Assets.getText(path), textureLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param object A String or ByteArray. */
|
/** @param object A String or ByteArray. */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user