Removed short names. Better project setup.

This commit is contained in:
NathanSweet 2014-05-19 16:19:48 +02:00
parent 4424a41411
commit 2157915a22
11 changed files with 514 additions and 1825 deletions

View File

@ -34,7 +34,7 @@
}; };
[skeletonNode setAnimationForTrack:0 name:@"walk" loop:YES]; [skeletonNode setAnimationForTrack:0 name:@"walk" loop:YES];
TrackEntry* jumpEntry = [skeletonNode addAnimationForTrack:0 name:@"jump" loop:NO afterDelay:3]; spTrackEntry* jumpEntry = [skeletonNode addAnimationForTrack:0 name:@"jump" loop:NO afterDelay:3];
[skeletonNode addAnimationForTrack:0 name:@"run" loop:YES afterDelay:0]; [skeletonNode addAnimationForTrack:0 name:@"run" loop:YES afterDelay:0];
[skeletonNode setListenerForEntry:jumpEntry onStart:^(int trackIndex) { [skeletonNode setListenerForEntry:jumpEntry onStart:^(int trackIndex) {

View File

@ -30,7 +30,7 @@
#import <spine/spine-cocos2d-iphone.h> #import <spine/spine-cocos2d-iphone.h>
@interface PolygonBatch : NSObject { @interface spPolygonBatch : NSObject {
int _capacity; int _capacity;
ccV2F_C4B_T2F* _vertices; ccV2F_C4B_T2F* _vertices;
int _verticesCount; int _verticesCount;

View File

@ -32,10 +32,10 @@
#import <spine/spine-cocos2d-iphone.h> #import <spine/spine-cocos2d-iphone.h>
#import <spine/extension.h> #import <spine/extension.h>
@implementation PolygonBatch @implementation spPolygonBatch
+ (id) createWithCapacity:(int)capacity { + (id) createWithCapacity:(int)capacity {
return [[(PolygonBatch*)[self alloc] initWithCapacity:capacity] autorelease]; return [[(spPolygonBatch*)[self alloc] initWithCapacity:capacity] autorelease];
} }
- (id) initWithCapacity:(int)capacity { - (id) initWithCapacity:(int)capacity {

View File

@ -28,59 +28,60 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#define SPINE_SHORT_NAMES
#import <spine/spine.h> #import <spine/spine.h>
#import <spine/SkeletonRenderer.h> #import <spine/SkeletonRenderer.h>
#import "cocos2d.h" #import "cocos2d.h"
@class SkeletonAnimation; @class SkeletonAnimation;
typedef void(^StartListener)(int trackIndex); typedef void(^spStartListener)(int trackIndex);
typedef void(^EndListener)(int trackIndex); typedef void(^spEndListener)(int trackIndex);
typedef void(^CompleteListener)(int trackIndex, int loopCount); typedef void(^spCompleteListener)(int trackIndex, int loopCount);
typedef void(^EventListener)(int trackIndex, spEvent* event); typedef void(^spEventListener)(int trackIndex, spEvent* event);
/** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be /** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be
* played later. */ * played later. */
@interface SkeletonAnimation : SkeletonRenderer { @interface SkeletonAnimation : SkeletonRenderer {
AnimationState* _state; spAnimationState* _state;
bool _ownsAnimationStateData; bool _ownsAnimationStateData;
float _timeScale;
StartListener _startListener; spStartListener _startListener;
EndListener _endListener; spEndListener _endListener;
CompleteListener _completeListener; spCompleteListener _completeListener;
EventListener _eventListener; spEventListener _eventListener;
} }
+ (id) skeletonWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData; + (id) skeletonWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale; + (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale;
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale; + (id) skeletonWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale;
- (id) initWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData; - (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale; - (id) initWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale;
- (id) initWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale; - (id) initWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale;
- (void) setAnimationStateData:(AnimationStateData*)stateData; - (void) setAnimationStateData:(spAnimationStateData*)stateData;
- (void) setMixFrom:(NSString*)fromAnimation to:(NSString*)toAnimation duration:(float)duration; - (void) setMixFrom:(NSString*)fromAnimation to:(NSString*)toAnimation duration:(float)duration;
- (TrackEntry*) setAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop; - (spTrackEntry*) setAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop;
- (TrackEntry*) addAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop afterDelay:(int)delay; - (spTrackEntry*) addAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop afterDelay:(int)delay;
- (TrackEntry*) getCurrentForTrack:(int)trackIndex; - (spTrackEntry*) getCurrentForTrack:(int)trackIndex;
- (void) clearTracks; - (void) clearTracks;
- (void) clearTrack:(int)trackIndex; - (void) clearTrack:(int)trackIndex;
- (void) setListenerForEntry:(spTrackEntry*)entry onStart:(StartListener)listener; - (void) setListenerForEntry:(spTrackEntry*)entry onStart:(spStartListener)listener;
- (void) setListenerForEntry:(spTrackEntry*)entry onEnd:(EndListener)listener; - (void) setListenerForEntry:(spTrackEntry*)entry onEnd:(spEndListener)listener;
- (void) setListenerForEntry:(spTrackEntry*)entry onComplete:(CompleteListener)listener; - (void) setListenerForEntry:(spTrackEntry*)entry onComplete:(spCompleteListener)listener;
- (void) setListenerForEntry:(spTrackEntry*)entry onEvent:(EventListener)listener; - (void) setListenerForEntry:(spTrackEntry*)entry onEvent:(spEventListener)listener;
- (void) onAnimationStateEvent:(int)trackIndex type:(EventType)type event:(Event*)event loopCount:(int)loopCount; - (void) onAnimationStateEvent:(int)trackIndex type:(spEventType)type event:(spEvent*)event loopCount:(int)loopCount;
- (void) onTrackEntryEvent:(int)trackIndex type:(EventType)type event:(Event*)event loopCount:(int)loopCount; - (void) onTrackEntryEvent:(int)trackIndex type:(spEventType)type event:(spEvent*)event loopCount:(int)loopCount;
@property (nonatomic, readonly) AnimationState* state; @property (nonatomic, readonly) spAnimationState* state;
@property (nonatomic, copy) StartListener startListener; @property (nonatomic) float timeScale;
@property (nonatomic, copy) EndListener endListener; @property (nonatomic, copy) spStartListener startListener;
@property (nonatomic, copy) CompleteListener completeListener; @property (nonatomic, copy) spEndListener endListener;
@property (nonatomic, copy) EventListener eventListener; @property (nonatomic, copy) spCompleteListener completeListener;
@property (nonatomic, copy) spEventListener eventListener;
@end @end

View File

@ -32,7 +32,7 @@
#import <spine/spine-cocos2d-iphone.h> #import <spine/spine-cocos2d-iphone.h>
#import <spine/extension.h> #import <spine/extension.h>
static void animationCallback (AnimationState* state, int trackIndex, EventType type, Event* event, int loopCount) { static void animationCallback (spAnimationState* state, int trackIndex, spEventType type, spEvent* event, int loopCount) {
[(SkeletonAnimation*)state->rendererObject onAnimationStateEvent:trackIndex type:type event:event loopCount:loopCount]; [(SkeletonAnimation*)state->rendererObject onAnimationStateEvent:trackIndex type:type event:event loopCount:loopCount];
} }
@ -41,10 +41,10 @@ void trackEntryCallback (spAnimationState* state, int trackIndex, spEventType ty
} }
typedef struct _TrackEntryListeners { typedef struct _TrackEntryListeners {
StartListener startListener; spStartListener startListener;
EndListener endListener; spEndListener endListener;
CompleteListener completeListener; spCompleteListener completeListener;
EventListener eventListener; spEventListener eventListener;
} _TrackEntryListeners; } _TrackEntryListeners;
static _TrackEntryListeners* getListeners (spTrackEntry* entry) { static _TrackEntryListeners* getListeners (spTrackEntry* entry) {
@ -76,16 +76,17 @@ void disposeTrackEntry (spTrackEntry* entry) {
@implementation SkeletonAnimation @implementation SkeletonAnimation
@synthesize state = _state; @synthesize state = _state;
@synthesize timeScale = _timeScale;
@synthesize startListener = _startListener; @synthesize startListener = _startListener;
@synthesize endListener = _endListener; @synthesize endListener = _endListener;
@synthesize completeListener = _completeListener; @synthesize completeListener = _completeListener;
@synthesize eventListener = _eventListener; @synthesize eventListener = _eventListener;
+ (id) skeletonWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData { + (id) skeletonWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
return [[[self alloc] initWithData:skeletonData ownsSkeletonData:ownsSkeletonData] autorelease]; return [[[self alloc] initWithData:skeletonData ownsSkeletonData:ownsSkeletonData] autorelease];
} }
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale { + (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale {
return [[[self alloc] initWithFile:skeletonDataFile atlas:atlas scale:scale] autorelease]; return [[[self alloc] initWithFile:skeletonDataFile atlas:atlas scale:scale] autorelease];
} }
@ -95,7 +96,9 @@ void disposeTrackEntry (spTrackEntry* entry) {
- (void) initialize { - (void) initialize {
_ownsAnimationStateData = true; _ownsAnimationStateData = true;
_state = AnimationState_create(AnimationStateData_create(_skeleton->data)); _timeScale = 1;
_state = spAnimationState_create(spAnimationStateData_create(_skeleton->data));
_state->rendererObject = self; _state->rendererObject = self;
_state->listener = animationCallback; _state->listener = animationCallback;
@ -103,7 +106,7 @@ void disposeTrackEntry (spTrackEntry* entry) {
stateInternal->disposeTrackEntry = disposeTrackEntry; stateInternal->disposeTrackEntry = disposeTrackEntry;
} }
- (id) initWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData { - (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
self = [super initWithData:skeletonData ownsSkeletonData:ownsSkeletonData]; self = [super initWithData:skeletonData ownsSkeletonData:ownsSkeletonData];
if (!self) return nil; if (!self) return nil;
@ -112,7 +115,7 @@ void disposeTrackEntry (spTrackEntry* entry) {
return self; return self;
} }
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale { - (id) initWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale {
self = [super initWithFile:skeletonDataFile atlas:atlas scale:scale]; self = [super initWithFile:skeletonDataFile atlas:atlas scale:scale];
if (!self) return nil; if (!self) return nil;
@ -131,8 +134,8 @@ void disposeTrackEntry (spTrackEntry* entry) {
} }
- (void) dealloc { - (void) dealloc {
if (_ownsAnimationStateData) AnimationStateData_dispose(_state->data); if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data);
AnimationState_dispose(_state); spAnimationState_dispose(_state);
[_startListener release]; [_startListener release];
[_endListener release]; [_endListener release];
@ -143,61 +146,60 @@ void disposeTrackEntry (spTrackEntry* entry) {
} }
- (void) update:(ccTime)deltaTime { - (void) update:(ccTime)deltaTime {
[super update:deltaTime];
deltaTime *= _timeScale; deltaTime *= _timeScale;
AnimationState_update(_state, deltaTime); spSkeleton_update(_skeleton, deltaTime);
AnimationState_apply(_state, _skeleton); spAnimationState_update(_state, deltaTime);
Skeleton_updateWorldTransform(_skeleton); spAnimationState_apply(_state, _skeleton);
spSkeleton_updateWorldTransform(_skeleton);
} }
- (void) setAnimationStateData:(AnimationStateData*)stateData { - (void) setAnimationStateData:(spAnimationStateData*)stateData {
NSAssert(stateData, @"stateData cannot be null."); NSAssert(stateData, @"stateData cannot be null.");
if (_ownsAnimationStateData) AnimationStateData_dispose(_state->data); if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data);
AnimationState_dispose(_state); spAnimationState_dispose(_state);
_ownsAnimationStateData = false; _ownsAnimationStateData = false;
_state = AnimationState_create(stateData); _state = spAnimationState_create(stateData);
_state->rendererObject = self; _state->rendererObject = self;
_state->listener = animationCallback; _state->listener = animationCallback;
} }
- (void) setMixFrom:(NSString*)fromAnimation to:(NSString*)toAnimation duration:(float)duration { - (void) setMixFrom:(NSString*)fromAnimation to:(NSString*)toAnimation duration:(float)duration {
AnimationStateData_setMixByName(_state->data, [fromAnimation UTF8String], [toAnimation UTF8String], duration); spAnimationStateData_setMixByName(_state->data, [fromAnimation UTF8String], [toAnimation UTF8String], duration);
} }
- (TrackEntry*) setAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop { - (spTrackEntry*) setAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop {
Animation* animation = SkeletonData_findAnimation(_skeleton->data, [name UTF8String]); spAnimation* animation = spSkeletonData_findAnimation(_skeleton->data, [name UTF8String]);
if (!animation) { if (!animation) {
CCLOG(@"Spine: Animation not found: %@", name); CCLOG(@"Spine: Animation not found: %@", name);
return 0; return 0;
} }
return AnimationState_setAnimation(_state, trackIndex, animation, loop); return spAnimationState_setAnimation(_state, trackIndex, animation, loop);
} }
- (TrackEntry*) addAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop afterDelay:(int)delay { - (spTrackEntry*) addAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop afterDelay:(int)delay {
Animation* animation = SkeletonData_findAnimation(_skeleton->data, [name UTF8String]); spAnimation* animation = spSkeletonData_findAnimation(_skeleton->data, [name UTF8String]);
if (!animation) { if (!animation) {
CCLOG(@"Spine: Animation not found: %@", name); CCLOG(@"Spine: Animation not found: %@", name);
return 0; return 0;
} }
return AnimationState_addAnimation(_state, trackIndex, animation, loop, delay); return spAnimationState_addAnimation(_state, trackIndex, animation, loop, delay);
} }
- (TrackEntry*) getCurrentForTrack:(int)trackIndex { - (spTrackEntry*) getCurrentForTrack:(int)trackIndex {
return AnimationState_getCurrent(_state, trackIndex); return spAnimationState_getCurrent(_state, trackIndex);
} }
- (void) clearTracks { - (void) clearTracks {
AnimationState_clearTracks(_state); spAnimationState_clearTracks(_state);
} }
- (void) clearTrack:(int)trackIndex { - (void) clearTrack:(int)trackIndex {
AnimationState_clearTrack(_state, trackIndex); spAnimationState_clearTrack(_state, trackIndex);
} }
- (void) onAnimationStateEvent:(int)trackIndex type:(EventType)type event:(Event*)event loopCount:(int)loopCount { - (void) onAnimationStateEvent:(int)trackIndex type:(spEventType)type event:(spEvent*)event loopCount:(int)loopCount {
switch (type) { switch (type) {
case SP_ANIMATION_START: case SP_ANIMATION_START:
if (_startListener) _startListener(trackIndex); if (_startListener) _startListener(trackIndex);
@ -214,7 +216,7 @@ void disposeTrackEntry (spTrackEntry* entry) {
} }
} }
- (void) onTrackEntryEvent:(int)trackIndex type:(EventType)type event:(Event*)event loopCount:(int)loopCount { - (void) onTrackEntryEvent:(int)trackIndex type:(spEventType)type event:(spEvent*)event loopCount:(int)loopCount {
spTrackEntry* entry = spAnimationState_getCurrent(_state, trackIndex); spTrackEntry* entry = spAnimationState_getCurrent(_state, trackIndex);
if (!entry->rendererObject) return; if (!entry->rendererObject) return;
_TrackEntryListeners* listeners = (_TrackEntryListeners*)entry->rendererObject; _TrackEntryListeners* listeners = (_TrackEntryListeners*)entry->rendererObject;
@ -234,19 +236,19 @@ void disposeTrackEntry (spTrackEntry* entry) {
} }
} }
- (void) setListenerForEntry:(spTrackEntry*)entry onStart:(StartListener)listener { - (void) setListenerForEntry:(spTrackEntry*)entry onStart:(spStartListener)listener {
getListeners(entry)->startListener = [listener copy]; getListeners(entry)->startListener = [listener copy];
} }
- (void) setListenerForEntry:(spTrackEntry*)entry onEnd:(EndListener)listener { - (void) setListenerForEntry:(spTrackEntry*)entry onEnd:(spEndListener)listener {
getListeners(entry)->endListener = [listener copy]; getListeners(entry)->endListener = [listener copy];
} }
- (void) setListenerForEntry:(spTrackEntry*)entry onComplete:(CompleteListener)listener { - (void) setListenerForEntry:(spTrackEntry*)entry onComplete:(spCompleteListener)listener {
getListeners(entry)->completeListener = [listener copy]; getListeners(entry)->completeListener = [listener copy];
} }
- (void) setListenerForEntry:(spTrackEntry*)entry onEvent:(EventListener)listener { - (void) setListenerForEntry:(spTrackEntry*)entry onEvent:(spEventListener)listener {
getListeners(entry)->eventListener = [listener copy]; getListeners(entry)->eventListener = [listener copy];
} }

View File

@ -28,39 +28,37 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#define SPINE_SHORT_NAMES
#import <spine/spine.h> #import <spine/spine.h>
#import "cocos2d.h" #import "cocos2d.h"
@class PolygonBatch; @class spPolygonBatch;
/** Draws a skeleton. */ /** Draws a skeleton. */
@interface SkeletonRenderer : CCNodeRGBA<CCBlendProtocol> { @interface SkeletonRenderer : CCNodeRGBA<CCBlendProtocol> {
Skeleton* _skeleton; spSkeleton* _skeleton;
Bone* _rootBone; spBone* _rootBone;
float _timeScale;
bool _debugSlots; bool _debugSlots;
bool _debugBones; bool _debugBones;
bool _premultipliedAlpha; bool _premultipliedAlpha;
ccBlendFunc _blendFunc; ccBlendFunc _blendFunc;
bool _ownsSkeletonData; bool _ownsSkeletonData;
Atlas* _atlas; spAtlas* _atlas;
PolygonBatch* batch; spPolygonBatch* batch;
float* worldVertices; float* worldVertices;
} }
+ (id) skeletonWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData; + (id) skeletonWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale; + (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale;
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale; + (id) skeletonWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale;
- (id) initWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData; - (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale; - (id) initWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale;
- (id) initWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale; - (id) initWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale;
- (CCTexture2D*) getTextureForRegion:(RegionAttachment*)attachment; - (CCTexture2D*) getTextureForRegion:(spRegionAttachment*)attachment;
- (CCTexture2D*) getTextureForMesh:(MeshAttachment*)attachment; - (CCTexture2D*) getTextureForMesh:(spMeshAttachment*)attachment;
- (CCTexture2D*) getTextureForSkinnedMesh:(SkinnedMeshAttachment*)attachment; - (CCTexture2D*) getTextureForSkinnedMesh:(spSkinnedMeshAttachment*)attachment;
// --- Convenience methods for common Skeleton_* functions. // --- Convenience methods for common Skeleton_* functions.
- (void) updateWorldTransform; - (void) updateWorldTransform;
@ -70,10 +68,10 @@
- (void) setSlotsToSetupPose; - (void) setSlotsToSetupPose;
/* Returns 0 if the bone was not found. */ /* Returns 0 if the bone was not found. */
- (Bone*) findBone:(NSString*)boneName; - (spBone*) findBone:(NSString*)boneName;
/* Returns 0 if the slot was not found. */ /* Returns 0 if the slot was not found. */
- (Slot*) findSlot:(NSString*)slotName; - (spSlot*) findSlot:(NSString*)slotName;
/* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are /* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are
* attached if the corresponding attachment from the old skin was attached. If there was no old skin, each slot's setup mode * attached if the corresponding attachment from the old skin was attached. If there was no old skin, each slot's setup mode
@ -82,14 +80,13 @@
- (bool) setSkin:(NSString*)skinName; - (bool) setSkin:(NSString*)skinName;
/* Returns 0 if the slot or attachment was not found. */ /* Returns 0 if the slot or attachment was not found. */
- (Attachment*) getAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName; - (spAttachment*) getAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName;
/* Returns false if the slot or attachment was not found. */ /* Returns false if the slot or attachment was not found. */
- (bool) setAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName; - (bool) setAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName;
@property (nonatomic, readonly) Skeleton* skeleton; @property (nonatomic, readonly) spSkeleton* skeleton;
@property (nonatomic) float timeScale;
@property (nonatomic) bool debugSlots; @property (nonatomic) bool debugSlots;
@property (nonatomic) bool debugBones; @property (nonatomic) bool debugBones;
@property (nonatomic) Bone* rootBone; @property (nonatomic) spBone* rootBone;
@end @end

View File

@ -36,22 +36,21 @@
static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0}; static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
@interface SkeletonRenderer (Private) @interface SkeletonRenderer (Private)
- (void) initialize:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData; - (void) initialize:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
@end @end
@implementation SkeletonRenderer @implementation SkeletonRenderer
@synthesize skeleton = _skeleton; @synthesize skeleton = _skeleton;
@synthesize rootBone = _rootBone; @synthesize rootBone = _rootBone;
@synthesize timeScale = _timeScale;
@synthesize debugSlots = _debugSlots; @synthesize debugSlots = _debugSlots;
@synthesize debugBones = _debugBones; @synthesize debugBones = _debugBones;
+ (id) skeletonWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData { + (id) skeletonWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
return [[[self alloc] initWithData:skeletonData ownsSkeletonData:ownsSkeletonData] autorelease]; return [[[self alloc] initWithData:skeletonData ownsSkeletonData:ownsSkeletonData] autorelease];
} }
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale { + (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale {
return [[[self alloc] initWithFile:skeletonDataFile atlas:atlas scale:scale] autorelease]; return [[[self alloc] initWithFile:skeletonDataFile atlas:atlas scale:scale] autorelease];
} }
@ -59,16 +58,14 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
return [[[self alloc] initWithFile:skeletonDataFile atlasFile:atlasFile scale:scale] autorelease]; return [[[self alloc] initWithFile:skeletonDataFile atlasFile:atlasFile scale:scale] autorelease];
} }
- (void) initialize:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData { - (void) initialize:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
_ownsSkeletonData = ownsSkeletonData; _ownsSkeletonData = ownsSkeletonData;
_timeScale = 1;
worldVertices = MALLOC(float, 1000); // Max number of vertices per mesh. worldVertices = MALLOC(float, 1000); // Max number of vertices per mesh.
batch = [[PolygonBatch createWithCapacity:2000] retain]; // Max number of vertices and triangles per batch. batch = [[spPolygonBatch createWithCapacity:2000] retain]; // Max number of vertices and triangles per batch.
_skeleton = Skeleton_create(skeletonData); _skeleton = spSkeleton_create(skeletonData);
_rootBone = _skeleton->bones[0]; _rootBone = _skeleton->bones[0];
_blendFunc.src = GL_ONE; _blendFunc.src = GL_ONE;
@ -79,7 +76,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
[self scheduleUpdate]; [self scheduleUpdate];
} }
- (id) initWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData { - (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
NSAssert(skeletonData, @"skeletonData cannot be null."); NSAssert(skeletonData, @"skeletonData cannot be null.");
self = [super init]; self = [super init];
@ -90,15 +87,15 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
return self; return self;
} }
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale { - (id) initWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale {
self = [super init]; self = [super init];
if (!self) return nil; if (!self) return nil;
SkeletonJson* json = SkeletonJson_create(atlas); spSkeletonJson* json = spSkeletonJson_create(atlas);
json->scale = scale == 0 ? (1 / CC_CONTENT_SCALE_FACTOR()) : scale; json->scale = scale / CC_CONTENT_SCALE_FACTOR();
SkeletonData* skeletonData = SkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]); spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
NSAssert(skeletonData, ([NSString stringWithFormat:@"Error reading skeleton data file: %@\nError: %s", skeletonDataFile, json->error])); NSAssert(skeletonData, ([NSString stringWithFormat:@"Error reading skeleton data file: %@\nError: %s", skeletonDataFile, json->error]));
SkeletonJson_dispose(json); spSkeletonJson_dispose(json);
if (!skeletonData) return 0; if (!skeletonData) return 0;
[self initialize:skeletonData ownsSkeletonData:YES]; [self initialize:skeletonData ownsSkeletonData:YES];
@ -110,15 +107,15 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
self = [super init]; self = [super init];
if (!self) return nil; if (!self) return nil;
_atlas = Atlas_createFromFile([atlasFile UTF8String], 0); _atlas = spAtlas_createFromFile([atlasFile UTF8String], 0);
NSAssert(_atlas, ([NSString stringWithFormat:@"Error reading atlas file: %@", atlasFile])); NSAssert(_atlas, ([NSString stringWithFormat:@"Error reading atlas file: %@", atlasFile]));
if (!_atlas) return 0; if (!_atlas) return 0;
SkeletonJson* json = SkeletonJson_create(_atlas); spSkeletonJson* json = spSkeletonJson_create(_atlas);
json->scale = scale == 0 ? (1 / CC_CONTENT_SCALE_FACTOR()) : scale; json->scale = scale / CC_CONTENT_SCALE_FACTOR();
SkeletonData* skeletonData = SkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]); spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
NSAssert(skeletonData, ([NSString stringWithFormat:@"Error reading skeleton data file: %@\nError: %s", skeletonDataFile, json->error])); NSAssert(skeletonData, ([NSString stringWithFormat:@"Error reading skeleton data file: %@\nError: %s", skeletonDataFile, json->error]));
SkeletonJson_dispose(json); spSkeletonJson_dispose(json);
if (!skeletonData) return 0; if (!skeletonData) return 0;
[self initialize:skeletonData ownsSkeletonData:YES]; [self initialize:skeletonData ownsSkeletonData:YES];
@ -127,18 +124,14 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
} }
- (void) dealloc { - (void) dealloc {
if (_ownsSkeletonData) SkeletonData_dispose(_skeleton->data); if (_ownsSkeletonData) spSkeletonData_dispose(_skeleton->data);
if (_atlas) Atlas_dispose(_atlas); if (_atlas) spAtlas_dispose(_atlas);
Skeleton_dispose(_skeleton); spSkeleton_dispose(_skeleton);
[batch release]; [batch release];
FREE(worldVertices); FREE(worldVertices);
[super dealloc]; [super dealloc];
} }
- (void) update:(ccTime)deltaTime {
Skeleton_update(_skeleton, deltaTime * _timeScale);
}
- (void) draw { - (void) draw {
CC_NODE_DRAW_SETUP(); CC_NODE_DRAW_SETUP();
@ -156,7 +149,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
int trianglesCount = 0; int trianglesCount = 0;
float r = 0, g = 0, b = 0, a = 0; float r = 0, g = 0, b = 0, a = 0;
for (int i = 0, n = _skeleton->slotCount; i < n; i++) { for (int i = 0, n = _skeleton->slotCount; i < n; i++) {
Slot* slot = _skeleton->drawOrder[i]; spSlot* slot = _skeleton->drawOrder[i];
if (!slot->attachment) continue; if (!slot->attachment) continue;
CCTexture2D *texture = 0; CCTexture2D *texture = 0;
switch (slot->attachment->type) { switch (slot->attachment->type) {
@ -227,9 +220,9 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
glLineWidth(1); glLineWidth(1);
CGPoint points[4]; CGPoint points[4];
for (int i = 0, n = _skeleton->slotCount; i < n; i++) { for (int i = 0, n = _skeleton->slotCount; i < n; i++) {
Slot* slot = _skeleton->drawOrder[i]; spSlot* slot = _skeleton->drawOrder[i];
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue; if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
RegionAttachment* attachment = (RegionAttachment*)slot->attachment; spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
spRegionAttachment_computeWorldVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, worldVertices); spRegionAttachment_computeWorldVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, worldVertices);
points[0] = ccp(worldVertices[0], worldVertices[1]); points[0] = ccp(worldVertices[0], worldVertices[1]);
points[1] = ccp(worldVertices[2], worldVertices[3]); points[1] = ccp(worldVertices[2], worldVertices[3]);
@ -243,7 +236,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
glLineWidth(2); glLineWidth(2);
ccDrawColor4B(255, 0, 0, 255); ccDrawColor4B(255, 0, 0, 255);
for (int i = 0, n = _skeleton->boneCount; i < n; i++) { for (int i = 0, n = _skeleton->boneCount; i < n; i++) {
Bone *bone = _skeleton->bones[i]; spBone *bone = _skeleton->bones[i];
float x = bone->data->length * bone->m00 + bone->worldX; float x = bone->data->length * bone->m00 + bone->worldX;
float y = bone->data->length * bone->m10 + bone->worldY; float y = bone->data->length * bone->m10 + bone->worldY;
ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y)); ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y));
@ -252,23 +245,23 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
ccPointSize(4); ccPointSize(4);
ccDrawColor4B(0, 0, 255, 255); // Root bone is blue. ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
for (int i = 0, n = _skeleton->boneCount; i < n; i++) { for (int i = 0, n = _skeleton->boneCount; i < n; i++) {
Bone *bone = _skeleton->bones[i]; spBone *bone = _skeleton->bones[i];
ccDrawPoint(ccp(bone->worldX, bone->worldY)); ccDrawPoint(ccp(bone->worldX, bone->worldY));
if (i == 0) ccDrawColor4B(0, 255, 0, 255); if (i == 0) ccDrawColor4B(0, 255, 0, 255);
} }
} }
} }
- (CCTexture2D*) getTextureForRegion:(RegionAttachment*)attachment { - (CCTexture2D*) getTextureForRegion:(spRegionAttachment*)attachment {
return (CCTexture2D*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject; return (CCTexture2D*)((spAtlasRegion*)attachment->rendererObject)->page->rendererObject;
} }
- (CCTexture2D*) getTextureForMesh:(MeshAttachment*)attachment { - (CCTexture2D*) getTextureForMesh:(spMeshAttachment*)attachment {
return (CCTexture2D*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject; return (CCTexture2D*)((spAtlasRegion*)attachment->rendererObject)->page->rendererObject;
} }
- (CCTexture2D*) getTextureForSkinnedMesh:(SkinnedMeshAttachment*)attachment { - (CCTexture2D*) getTextureForSkinnedMesh:(spSkinnedMeshAttachment*)attachment {
return (CCTexture2D*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject; return (CCTexture2D*)((spAtlasRegion*)attachment->rendererObject)->page->rendererObject;
} }
- (CGRect) boundingBox { - (CGRect) boundingBox {
@ -277,26 +270,26 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
float scaleY = self.scaleY; float scaleY = self.scaleY;
float vertices[8]; float vertices[8];
for (int i = 0; i < _skeleton->slotCount; ++i) { for (int i = 0; i < _skeleton->slotCount; ++i) {
Slot* slot = _skeleton->slots[i]; spSlot* slot = _skeleton->slots[i];
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue; if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
RegionAttachment* attachment = (RegionAttachment*)slot->attachment; spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
RegionAttachment_computeWorldVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices); spRegionAttachment_computeWorldVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices);
minX = fmin(minX, vertices[VERTEX_X1] * scaleX); minX = fmin(minX, vertices[SP_VERTEX_X1] * scaleX);
minY = fmin(minY, vertices[VERTEX_Y1] * scaleY); minY = fmin(minY, vertices[SP_VERTEX_Y1] * scaleY);
maxX = fmax(maxX, vertices[VERTEX_X1] * scaleX); maxX = fmax(maxX, vertices[SP_VERTEX_X1] * scaleX);
maxY = fmax(maxY, vertices[VERTEX_Y1] * scaleY); maxY = fmax(maxY, vertices[SP_VERTEX_Y1] * scaleY);
minX = fmin(minX, vertices[VERTEX_X4] * scaleX); minX = fmin(minX, vertices[SP_VERTEX_X4] * scaleX);
minY = fmin(minY, vertices[VERTEX_Y4] * scaleY); minY = fmin(minY, vertices[SP_VERTEX_Y4] * scaleY);
maxX = fmax(maxX, vertices[VERTEX_X4] * scaleX); maxX = fmax(maxX, vertices[SP_VERTEX_X4] * scaleX);
maxY = fmax(maxY, vertices[VERTEX_Y4] * scaleY); maxY = fmax(maxY, vertices[SP_VERTEX_Y4] * scaleY);
minX = fmin(minX, vertices[VERTEX_X2] * scaleX); minX = fmin(minX, vertices[SP_VERTEX_X2] * scaleX);
minY = fmin(minY, vertices[VERTEX_Y2] * scaleY); minY = fmin(minY, vertices[SP_VERTEX_Y2] * scaleY);
maxX = fmax(maxX, vertices[VERTEX_X2] * scaleX); maxX = fmax(maxX, vertices[SP_VERTEX_X2] * scaleX);
maxY = fmax(maxY, vertices[VERTEX_Y2] * scaleY); maxY = fmax(maxY, vertices[SP_VERTEX_Y2] * scaleY);
minX = fmin(minX, vertices[VERTEX_X3] * scaleX); minX = fmin(minX, vertices[SP_VERTEX_X3] * scaleX);
minY = fmin(minY, vertices[VERTEX_Y3] * scaleY); minY = fmin(minY, vertices[SP_VERTEX_Y3] * scaleY);
maxX = fmax(maxX, vertices[VERTEX_X3] * scaleX); maxX = fmax(maxX, vertices[SP_VERTEX_X3] * scaleX);
maxY = fmax(maxY, vertices[VERTEX_Y3] * scaleY); maxY = fmax(maxY, vertices[SP_VERTEX_Y3] * scaleY);
} }
minX = self.position.x + minX; minX = self.position.x + minX;
minY = self.position.y + minY; minY = self.position.y + minY;
@ -308,36 +301,36 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
// --- Convenience methods for Skeleton_* functions. // --- Convenience methods for Skeleton_* functions.
- (void) updateWorldTransform { - (void) updateWorldTransform {
Skeleton_updateWorldTransform(_skeleton); spSkeleton_updateWorldTransform(_skeleton);
} }
- (void) setToSetupPose { - (void) setToSetupPose {
Skeleton_setToSetupPose(_skeleton); spSkeleton_setToSetupPose(_skeleton);
} }
- (void) setBonesToSetupPose { - (void) setBonesToSetupPose {
Skeleton_setBonesToSetupPose(_skeleton); spSkeleton_setBonesToSetupPose(_skeleton);
} }
- (void) setSlotsToSetupPose { - (void) setSlotsToSetupPose {
Skeleton_setSlotsToSetupPose(_skeleton); spSkeleton_setSlotsToSetupPose(_skeleton);
} }
- (Bone*) findBone:(NSString*)boneName { - (spBone*) findBone:(NSString*)boneName {
return Skeleton_findBone(_skeleton, [boneName UTF8String]); return spSkeleton_findBone(_skeleton, [boneName UTF8String]);
} }
- (Slot*) findSlot:(NSString*)slotName { - (spSlot*) findSlot:(NSString*)slotName {
return Skeleton_findSlot(_skeleton, [slotName UTF8String]); return spSkeleton_findSlot(_skeleton, [slotName UTF8String]);
} }
- (bool) setSkin:(NSString*)skinName { - (bool) setSkin:(NSString*)skinName {
return (bool)Skeleton_setSkinByName(_skeleton, skinName ? [skinName UTF8String] : 0); return (bool)spSkeleton_setSkinByName(_skeleton, skinName ? [skinName UTF8String] : 0);
} }
- (Attachment*) getAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName { - (spAttachment*) getAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName {
return Skeleton_getAttachmentForSlotName(_skeleton, [slotName UTF8String], [attachmentName UTF8String]); return spSkeleton_getAttachmentForSlotName(_skeleton, [slotName UTF8String], [attachmentName UTF8String]);
} }
- (bool) setAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName { - (bool) setAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName {
return (bool)Skeleton_setAttachment(_skeleton, [slotName UTF8String], [attachmentName UTF8String]); return (bool)spSkeleton_setAttachment(_skeleton, [slotName UTF8String], [attachmentName UTF8String]);
} }
// --- CCBlendProtocol // --- CCBlendProtocol

View File

@ -28,7 +28,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#define SPINE_SHORT_NAMES
#import <spine/spine.h> #import <spine/spine.h>
#import "cocos2d.h" #import "cocos2d.h"
#import <spine/SkeletonRenderer.h> #import <spine/SkeletonRenderer.h>

View File

@ -31,7 +31,7 @@
#import <spine/spine-cocos2d-iphone.h> #import <spine/spine-cocos2d-iphone.h>
#import <spine/extension.h> #import <spine/extension.h>
void _AtlasPage_createTexture (AtlasPage* self, const char* path) { void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) {
CCTexture2D* texture = [[[CCTextureCache sharedTextureCache] addImage:@(path)] retain]; CCTexture2D* texture = [[[CCTextureCache sharedTextureCache] addImage:@(path)] retain];
self->rendererObject = texture; self->rendererObject = texture;
CGSize size = texture.contentSizeInPixels; CGSize size = texture.contentSizeInPixels;
@ -39,10 +39,10 @@ void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
self->height = size.height; self->height = size.height;
} }
void _AtlasPage_disposeTexture (AtlasPage* self) { void _spAtlasPage_disposeTexture (spAtlasPage* self) {
[(CCTexture2D*)self->rendererObject release]; [(CCTexture2D*)self->rendererObject release];
} }
char* _Util_readFile (const char* path, int* length) { char* _spUtil_readFile (const char* path, int* length) {
return _readFile([[[CCFileUtils sharedFileUtils] fullPathForFilename:@(path)] UTF8String], length); return _readFile([[[CCFileUtils sharedFileUtils] fullPathForFilename:@(path)] UTF8String], length);
} }