FlxSpine (SpineHaxe) and collision detection question

78 views
Skip to first unread message

jhice

unread,
Mar 31, 2015, 9:26:08 AM3/31/15
to haxef...@googlegroups.com
Hi,

I've managed to use the updated FlxSpine/SpineHaxe in the dev branch of HaxeFlixel.

Since, I managed to intercept the events from Spine.

The problem I face now is to check collisions between the bones themselves or even the FlxSpine objects themselves. I cant get a collision to true.
  • I tried to use the collider helper at FlxSpine.hx line 78, with overlap, but the collider width and height are at zero instead of being at the size of the FlxSpine object, like this :
FlxG.log.add(FlxG.overlap(this.collider, Reg.enemy.collider));

It returns false even when my two FlxSpine objects overlap.
  • I saw 2 other ways to check collision but dont really know how to handle it and if it is the right way to do it :
    • testing overlap of the FlxSprites attached to the bones (as seen in FlxSpine.hx line 444,
    • use the built-in collision checking bounds.aabbContainsPoint(point.x, point.y) (but does not check objects, just points).
I'd like to do exactly this (first post) http://forum.haxepunk.com/index.php?topic=641.0 but I think I'm misusing the library.

Any help appreciated.
Thanks.

PS : my traces are not working anymore that is why I use the flixel debugger.

jhice

unread,
Mar 31, 2015, 1:04:33 PM3/31/15
to haxef...@googlegroups.com
Well, I know my post lacks some code but this is not so easy to put in place...

While searching with my mate at the animations we realized we have defined no bounding boxes in Spine, and it is used to check the collisions.
We try this and I'll tell you ;)

jhice

unread,
Apr 1, 2015, 11:54:17 AM4/1/15
to haxef...@googlegroups.com
Well, we're on the right way...

It seems the "best" way is to use the built-in methods for intersection checks.
If you want to check some bounding boxes from different Spine animations, let's say "hero" and "enemy", you could do :

  • create a public var bounds:SkeletonBounds; in each FlxSpine object,
  • in the new function, do a call to bounds = new SkeletonBounds(); to instantiate the bounds object needed for collision checks, and in the same function add a listener to the state this way : state.onEvent.add(onEvent);,
  • create the function onEvent (or whatever you want to name it) :
private function onEvent(trackIndex:Int, event:Event):Void
{
  // Update "this" SkeletonBounds with current skeleton bounding box positions (the ones created in Spine, important !)
  bounds.update(skeleton, true);

  // The same for the enemy skeleton
  Reg.enemy.bounds.update(Reg.enemy.skeleton, true);

  // Trace the event name you added into Spine (not used here because just testing on event = hit)
  FlxG.log.add("Track:" + trackIndex + "=" + state.getCurrent(trackIndex) + ", Event: " + event);

  // Use the built-in method to check collisions between the "meta" bounding box of the two objects
  // "meta" bouding box is the bouding box surrounding all the bounding boxes
  FlxG.log.add(bounds.aabbIntersectsSkeleton(Reg.enemy.bounds));
}

The aabbIntersectsSkeleton function will return true or false if the big bounding box of "hero" intersects the "enemy" one.

You can help yourself visualizing your skeletons, bones and bounds with the Java viewer from Esoteric : http://fr.esotericsoftware.com/spine-skeleton-viewer if you dont have Spine but just the exported data. Very usefull.

From here, if this returns true, it is time to check the intersection of a particular hero polygon (weapon) with others enemy polygons (head, body etc.).

It will be the next part ;)

Le mardi 31 mars 2015 15:26:08 UTC+2, jhice a écrit :
Reply all
Reply to author
Forward
0 new messages