diff --git a/spine-haxe/README.md b/spine-haxe/README.md index 7601fe34b..e96237c40 100644 --- a/spine-haxe/README.md +++ b/spine-haxe/README.md @@ -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. -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`. diff --git a/spine-haxe/example/src/BasicExample.hx b/spine-haxe/example/src/BasicExample.hx index 6e29895fc..b330f09b3 100644 --- a/spine-haxe/example/src/BasicExample.hx +++ b/spine-haxe/example/src/BasicExample.hx @@ -1,9 +1,10 @@ -import openfl.geom.Rectangle; 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 BasicExample extends Scene { var loadBinary = true; @@ -24,5 +25,14 @@ class BasicExample extends Scene { 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"); + } } } diff --git a/spine-haxe/example/src/Main.hx b/spine-haxe/example/src/Main.hx index 96995bfb2..1c0617cb9 100644 --- a/spine-haxe/example/src/Main.hx +++ b/spine-haxe/example/src/Main.hx @@ -22,6 +22,6 @@ class Main extends Sprite { starlingSingleton.start(); Starling.current.stage.color = 0x000000; - SceneManager.getInstance().switchScene(new BasicExample()); + SceneManager.getInstance().switchScene(new SequenceExample()); } } diff --git a/spine-haxe/example/src/Scene.hx b/spine-haxe/example/src/Scene.hx index 64b7cf4f0..399091ddf 100644 --- a/spine-haxe/example/src/Scene.hx +++ b/spine-haxe/example/src/Scene.hx @@ -1,3 +1,5 @@ +import starling.utils.Color; +import starling.display.Quad; import starling.core.Starling; import starling.display.Sprite; diff --git a/spine-haxe/example/src/SequenceExample.hx b/spine-haxe/example/src/SequenceExample.hx new file mode 100644 index 000000000..64bc9d17a --- /dev/null +++ b/spine-haxe/example/src/SequenceExample.hx @@ -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"); + } + } +} diff --git a/spine-haxe/spine-haxe/spine/SkeletonJson.hx b/spine-haxe/spine-haxe/spine/SkeletonJson.hx index 873d72dbd..6b33758a7 100644 --- a/spine-haxe/spine-haxe/spine/SkeletonJson.hx +++ b/spine-haxe/spine-haxe/spine/SkeletonJson.hx @@ -929,7 +929,7 @@ class SkeletonJson { throw new SpineException("Slot not found: " + slotMapName); for (attachmentMapName in slotMap) { var attachmentMap = slotMap[attachmentMapName]; - var attachment:VertexAttachment = cast(skin.getAttachment(slotIndex, attachmentMapName), VertexAttachment); + var attachment:Attachment = skin.getAttachment(slotIndex, attachmentMapName); if (attachment == null) throw new SpineException("Timeline attachment not found: " + attachmentMapName); @@ -940,11 +940,12 @@ class SkeletonJson { continue; if (timelineMapName == "deform") { - var weighted:Bool = attachment.bones != null; - var vertices:Vector = attachment.vertices; + var vertexAttachment = cast(attachment, VertexAttachment); + var weighted:Bool = vertexAttachment.bones != null; + var vertices:Vector = vertexAttachment.vertices; 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"); frame = 0; bezier = 0; diff --git a/spine-haxe/spine-haxe/spine/atlas/TextureAtlas.hx b/spine-haxe/spine-haxe/spine/atlas/TextureAtlas.hx index b965a90de..ef39fa2e2 100644 --- a/spine-haxe/spine-haxe/spine/atlas/TextureAtlas.hx +++ b/spine-haxe/spine-haxe/spine/atlas/TextureAtlas.hx @@ -19,7 +19,7 @@ class TextureAtlas { } 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. */