Added AnimationState clear.

id return value for factory methods.
This commit is contained in:
NathanSweet 2013-04-18 23:30:39 +02:00
parent 7193122908
commit 7bd6f62a2b
9 changed files with 24 additions and 9 deletions

View File

@ -52,6 +52,7 @@ void AnimationState_apply (AnimationState* self, struct Skeleton* skeleton);
void AnimationState_setAnimationByName (AnimationState* self, const char* animationName, int/**/loop);
/* @param animation May be 0. */
void AnimationState_setAnimation (AnimationState* self, Animation* animation, int/**/loop);
void AnimationState_clearAnimation (AnimationState* self);
#ifdef __cplusplus
}

View File

@ -92,6 +92,11 @@ void AnimationState_setAnimation (AnimationState* self, Animation* newAnimation,
self->time = 0;
}
void AnimationState_clearAnimation (AnimationState* self) {
SUB_CAST(_Internal, self) ->previous = 0;
CONST_CAST(Animation*, self->animation) = 0;
}
#ifdef __cplusplus
}
#endif

View File

@ -59,6 +59,7 @@
- (void) setMix:(NSString*)fromName to:(NSString*)toName duration:(float)duration;
- (void) setAnimation:(NSString*)animationName loop:(bool)loop;
- (void) clearAnimation;
- (void) updateWorldTransform;

View File

@ -112,11 +112,11 @@ void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_
@implementation CCSkeleton
+ (CCSkeleton*) create:(NSString*)skeletonDataFile atlas:(Atlas*)atlas {
+ (id) create:(NSString*)skeletonDataFile atlas:(Atlas*)atlas {
return [CCSkeleton create:skeletonDataFile atlas:atlas scale:1];
}
+ (CCSkeleton*) create:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale {
+ (id) create:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale {
NSAssert(skeletonDataFile, @"skeletonDataFile cannot be nil.");
NSAssert(atlas, @"atlas cannot be nil.");
@ -131,11 +131,11 @@ void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_
return node;
}
+ (CCSkeleton*) create:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile {
+ (id) create:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile {
return [CCSkeleton create:skeletonDataFile atlasFile:atlasFile scale:1];
}
+ (CCSkeleton*) create:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale {
+ (id) create:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale {
NSAssert(skeletonDataFile, @"skeletonDataFile cannot be nil.");
NSAssert(atlasFile, @"atlasFile cannot be nil.");
@ -159,11 +159,11 @@ void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_
return node;
}
+ (CCSkeleton*) create:(SkeletonData*)skeletonData {
+ (id) create:(SkeletonData*)skeletonData {
return [CCSkeleton create:skeletonData stateData:0];
}
+ (CCSkeleton*) create:(SkeletonData*)skeletonData stateData:(AnimationStateData*)stateData {
+ (id) create:(SkeletonData*)skeletonData stateData:(AnimationStateData*)stateData {
return [[[CCSkeleton alloc] init:skeletonData stateData:stateData] autorelease];
}
@ -330,6 +330,9 @@ void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_
- (void) setAnimation:(NSString*)animationName loop:(bool)loop {
AnimationState_setAnimationByName(state, [animationName UTF8String], loop);
}
- (void) clearAnimation {
AnimationState_clearAnimation(state);
}
- (void) updateWorldTransform {
Skeleton_updateWorldTransform(skeleton);

View File

@ -299,6 +299,10 @@ void CCSkeleton::setAnimation (const char* animationName, bool loop) {
AnimationState_setAnimationByName(state, animationName, loop);
}
void CCSkeleton::clearAnimation () {
AnimationState_clearAnimation(state);
}
void CCSkeleton::updateWorldTransform () {
Skeleton_updateWorldTransform(skeleton);
}

View File

@ -53,6 +53,7 @@ public:
void setMix (const char* fromName, const char* toName, float duration);
void setAnimation (const char* animationName, bool loop);
void clearAnimation ();
void updateWorldTransform ();

View File

@ -84,7 +84,7 @@ namespace Spine {
Time = 0;
}
public void Clear () {
public void ClearAnimation () {
previous = null;
Animation = null;
}

View File

@ -60,7 +60,7 @@ public class AnimationState {
current.apply(skeleton, currentTime, currentLoop);
}
public void clear () {
public void clearAnimation () {
previous = null;
current = null;
}

View File

@ -74,7 +74,7 @@ public class SkeletonComponent : MonoBehaviour {
// Keep AnimationState in sync with animationName and loop fields.
if (animationName == null && state.Animation != null)
state.Clear();
state.ClearAnimation();
else if (state.Animation == null || animationName != state.Animation.Name) {
Spine.Animation animation = skeleton.Data.FindAnimation(animationName);
if (animation != null)