- Modifié
Get X,Y position of a bone
Is there a way to get the X,Y position of a bone within a Spine? I have been looking through the API documentation and feel like it is possible with the collection of objects, but not sure if it is simple or difficult.
I'm specifically interested in getting the exact position of a bone ("Pistol" or a bone I'd create "Firepoint") that would help place a VFX within an animation at an exact X, Y position. In this case, I'd be putting in both an animation for the gunfire, as well as the streak of the bullet emanating from the point. You can see why it would be better to get an X,Y from the spine, otherwise it will just never line up well enough.
Or, is there is a better method for this kind of idea?
Thanks in advance for your time.
a Bone has float fields x
and y
which are local values. It also has worldX
and worldY
.
You need to get them at the correct time though (ie, after the skeleton updates in that frame). That depends on whatever framework/engine you're using.
Pharan a écrita Bone has float fields
x
andy
which are local values. It also hasworldX
andworldY
.
You need to get them at the correct time though (ie, after the skeleton updates in that frame). That depends on whatever framework/engine you're using.
Ok, that is helpful, and nice and simple. You all do great work. SkeletonData.findBone("Firepoint").x, etc
We're using Cocos2DX. Any suggestions on how to get time it so we get the right X,Y from the correct frame / second?
I was look at the Events API to see if we could use it to alert the game engine to the right frame.
Thanks for the early tip
I've got events setup and a listener firing. I need to learn a bit more about C++ lambdas to be able to get access to the skeleton, but I think I've got everything I need to set this up. Just ... must teach my animator brain some more C++. My engineering brother is out of town for the weekend.
@Pharan - thanks again for helping me out. The lambda capture clause was simpler than expected.
I've got everything I need coming out in the log
0 event: Pistol Fire, 0, 0.000000, (null)
Found Bone at 51.459999, -31.209999 rotation 3.040000
For spine-cocos2dx it's like this:
spBone* firePoint = skeletonNode->findBone("Firepoint");
spEventData* fireEvent = spSkeletonData_findEvent(skeletonNode->getSkeleton()->data, "Fire");
skeletonNode->setEventListener( [fireEvent, firePoint] (int trackIndex, spEvent* event) {
if (event->data == fireEvent) log("fire! %f, %f", firePoint->worldX, firePoint->worldY);
});
This avoids string comparisons on the event name and avoids looking up the bone by name many times.
Nate a écritFor spine-cocos2dx it's like this:
spBone* firePoint = skeletonNode->findBone("Firepoint"); spEventData* fireEvent = spSkeletonData_findEvent(skeletonNode->getSkeleton()->data, "Fire"); skeletonNode->setEventListener( [fireEvent, firePoint] (int trackIndex, spEvent* event) { if (event->data == fireEvent) log("fire! %f, %f", firePoint->worldX, firePoint->worldY); });
This avoids string comparisons on the event name and avoids looking up the bone by name many times.
Thank you for the extra performance pointers, very appreciated!