Hi,
I can't seem to calculate a bounding box for a Spine attachment. Below is the complete code for a Goblin actor. The name of the class is Goblin but I'm using the Spine Boy animation from the Spine examples directory. What I'm trying to do is to catch taps on the gun the boy holds. I created a bounding box that is going to wrap the area the gun occupies and exported the JSON from Spine. The code below shows the animation and bounding box configuration.
package {
import spine.Skeleton;
import spine.SkeletonBounds;
import spine.SkeletonData;
import spine.SkeletonJson;
import spine.animation.AnimationStateData;
import spine.attachments.AttachmentLoader;
import spine.starling.SkeletonAnimation;
import spine.starling.StarlingAtlasAttachmentLoader;
import starling.core.Starling;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
public class Goblin extends ZRSprite {
[Embed(source="/resource/spine/spineboy.json", mimeType="application/octet-stream")]
static public const GoblinsJson:Class;
private var skeleton:Skeleton;
private var skeletonAnimation:SkeletonAnimation;
private var skeletonBounds:SkeletonBounds = new SkeletonBounds();
public function Goblin() {
var attachmentLoader:AttachmentLoader = new StarlingAtlasAttachmentLoader(Assets.getTextureAtlas('atlas0'));
var json:SkeletonJson = new SkeletonJson(attachmentLoader);
var skeletonData:SkeletonData = json.readSkeletonData(new GoblinsJson());
skeleton = new Skeleton(skeletonData);
skeleton.setAttachment('gun', 'gun-bounding-box');
var stateData:AnimationStateData = new AnimationStateData(skeletonData);
stateData.setMixByName("run", "jump", 0.3);
stateData.setMixByName("jump", "run", 0);
skeletonAnimation = new SkeletonAnimation(skeletonData, true);
skeletonAnimation.skeleton.setSlotsToSetupPose();
skeletonAnimation.state.setAnimationByName(0, "run", true);
skeletonAnimation.timeScale = 0.1;
addChild(skeletonAnimation);
Starling.juggler.add(skeletonAnimation);
addEventListener(TouchEvent.TOUCH, onClick);
}
private function onClick(event:TouchEvent):void {
var touch:Touch = event.getTouch(this);
if (touch && touch.phase == TouchPhase.ENDED) {
skeletonBounds.update(skeleton, true);
trace(skeletonBounds.aabbContainsPoint(touch.getLocation(skeletonAnimation).x, touch.getLocation(skeletonAnimation).y));
}
}
}
}
Inside the onClick handler, skeletonBounds are updated. I can see the bounding boxes are created. See the screenshot please:
Loading Image
Yet, I can't get a "true" output when I click on the animation.