- Modifié
Possible Issue with (spSkeletonBounds_update)
Hi, I believe there is an issue with :spSkeletonBounds_update in the context of cocos2d.
Basically I want to work out the height of the character at certain time in the animation before playing the animation:
// First get the height of the avatar by working out the distance between min and max
[[somelayer animation] setFrameForAnimation:someanimation withTime:0.6];
[somelayer getSnippetHeight];
[[somelayer animation] setFrameForAnimation:someanimation withTime:0.0];
[somelayer setVisible:YES];
[somelayer setPosition:ccp(posX, posY)];
[[somelayer animation] setScale:self.somelayerscale];
[[somelayer animation] setAnimationForTrack:0 name:someanimation loop:NO];
(void)getSnippetHeight
{
spSkeletonBounds *bounds = spSkeletonBounds_create();
spSkeletonBounds_update(bounds, [animation skeleton], 1);
NSLog(@"min: %f, max: %f", bounds->minY, bounds->maxY);
spSkeletonBounds_dispose(bounds);
}
The problem:
It keeps reporting the max and min from the setup pose rather than from the time in the animation from which I want it.
Thank you in advance
Not sure what setFrameForAnimation is. To do what you want, but you need to apply the animation, update the bone's world transform, then use SkeletonBounds. setAnimationForTrack is convenience for AnimationState_setAnimation, but you haven't applied it or done update world transform. Try calling [[somelayer animation] update:0] to do this.
Thanks Nate,
Updating world transform works :-)
Kindest Regards