mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-27 20:21:24 +08:00
Removed short names. Better project setup.
This commit is contained in:
parent
4424a41411
commit
2157915a22
@ -34,7 +34,7 @@
|
||||
};
|
||||
|
||||
[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 setListenerForEntry:jumpEntry onStart:^(int trackIndex) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,7 @@
|
||||
|
||||
#import <spine/spine-cocos2d-iphone.h>
|
||||
|
||||
@interface PolygonBatch : NSObject {
|
||||
@interface spPolygonBatch : NSObject {
|
||||
int _capacity;
|
||||
ccV2F_C4B_T2F* _vertices;
|
||||
int _verticesCount;
|
||||
|
||||
@ -32,10 +32,10 @@
|
||||
#import <spine/spine-cocos2d-iphone.h>
|
||||
#import <spine/extension.h>
|
||||
|
||||
@implementation PolygonBatch
|
||||
@implementation spPolygonBatch
|
||||
|
||||
+ (id) createWithCapacity:(int)capacity {
|
||||
return [[(PolygonBatch*)[self alloc] initWithCapacity:capacity] autorelease];
|
||||
return [[(spPolygonBatch*)[self alloc] initWithCapacity:capacity] autorelease];
|
||||
}
|
||||
|
||||
- (id) initWithCapacity:(int)capacity {
|
||||
|
||||
@ -28,59 +28,60 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#define SPINE_SHORT_NAMES
|
||||
#import <spine/spine.h>
|
||||
#import <spine/SkeletonRenderer.h>
|
||||
#import "cocos2d.h"
|
||||
|
||||
@class SkeletonAnimation;
|
||||
|
||||
typedef void(^StartListener)(int trackIndex);
|
||||
typedef void(^EndListener)(int trackIndex);
|
||||
typedef void(^CompleteListener)(int trackIndex, int loopCount);
|
||||
typedef void(^EventListener)(int trackIndex, spEvent* event);
|
||||
typedef void(^spStartListener)(int trackIndex);
|
||||
typedef void(^spEndListener)(int trackIndex);
|
||||
typedef void(^spCompleteListener)(int trackIndex, int loopCount);
|
||||
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
|
||||
* played later. */
|
||||
@interface SkeletonAnimation : SkeletonRenderer {
|
||||
AnimationState* _state;
|
||||
spAnimationState* _state;
|
||||
bool _ownsAnimationStateData;
|
||||
float _timeScale;
|
||||
|
||||
StartListener _startListener;
|
||||
EndListener _endListener;
|
||||
CompleteListener _completeListener;
|
||||
EventListener _eventListener;
|
||||
spStartListener _startListener;
|
||||
spEndListener _endListener;
|
||||
spCompleteListener _completeListener;
|
||||
spEventListener _eventListener;
|
||||
}
|
||||
|
||||
+ (id) skeletonWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale;
|
||||
+ (id) skeletonWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale;
|
||||
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale;
|
||||
|
||||
- (id) initWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale;
|
||||
- (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas 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;
|
||||
|
||||
- (TrackEntry*) setAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop;
|
||||
- (TrackEntry*) addAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop afterDelay:(int)delay;
|
||||
- (TrackEntry*) getCurrentForTrack:(int)trackIndex;
|
||||
- (spTrackEntry*) setAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop;
|
||||
- (spTrackEntry*) addAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop afterDelay:(int)delay;
|
||||
- (spTrackEntry*) getCurrentForTrack:(int)trackIndex;
|
||||
- (void) clearTracks;
|
||||
- (void) clearTrack:(int)trackIndex;
|
||||
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onStart:(StartListener)listener;
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onEnd:(EndListener)listener;
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onComplete:(CompleteListener)listener;
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onEvent:(EventListener)listener;
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onStart:(spStartListener)listener;
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onEnd:(spEndListener)listener;
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onComplete:(spCompleteListener)listener;
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onEvent:(spEventListener)listener;
|
||||
|
||||
- (void) onAnimationStateEvent:(int)trackIndex type:(EventType)type event:(Event*)event loopCount:(int)loopCount;
|
||||
- (void) onTrackEntryEvent:(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:(spEventType)type event:(spEvent*)event loopCount:(int)loopCount;
|
||||
|
||||
@property (nonatomic, readonly) AnimationState* state;
|
||||
@property (nonatomic, copy) StartListener startListener;
|
||||
@property (nonatomic, copy) EndListener endListener;
|
||||
@property (nonatomic, copy) CompleteListener completeListener;
|
||||
@property (nonatomic, copy) EventListener eventListener;
|
||||
@property (nonatomic, readonly) spAnimationState* state;
|
||||
@property (nonatomic) float timeScale;
|
||||
@property (nonatomic, copy) spStartListener startListener;
|
||||
@property (nonatomic, copy) spEndListener endListener;
|
||||
@property (nonatomic, copy) spCompleteListener completeListener;
|
||||
@property (nonatomic, copy) spEventListener eventListener;
|
||||
|
||||
@end
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
#import <spine/spine-cocos2d-iphone.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];
|
||||
}
|
||||
|
||||
@ -41,10 +41,10 @@ void trackEntryCallback (spAnimationState* state, int trackIndex, spEventType ty
|
||||
}
|
||||
|
||||
typedef struct _TrackEntryListeners {
|
||||
StartListener startListener;
|
||||
EndListener endListener;
|
||||
CompleteListener completeListener;
|
||||
EventListener eventListener;
|
||||
spStartListener startListener;
|
||||
spEndListener endListener;
|
||||
spCompleteListener completeListener;
|
||||
spEventListener eventListener;
|
||||
} _TrackEntryListeners;
|
||||
|
||||
static _TrackEntryListeners* getListeners (spTrackEntry* entry) {
|
||||
@ -76,16 +76,17 @@ void disposeTrackEntry (spTrackEntry* entry) {
|
||||
@implementation SkeletonAnimation
|
||||
|
||||
@synthesize state = _state;
|
||||
@synthesize timeScale = _timeScale;
|
||||
@synthesize startListener = _startListener;
|
||||
@synthesize endListener = _endListener;
|
||||
@synthesize completeListener = _completeListener;
|
||||
@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];
|
||||
}
|
||||
|
||||
+ (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];
|
||||
}
|
||||
|
||||
@ -95,7 +96,9 @@ void disposeTrackEntry (spTrackEntry* entry) {
|
||||
|
||||
- (void) initialize {
|
||||
_ownsAnimationStateData = true;
|
||||
_state = AnimationState_create(AnimationStateData_create(_skeleton->data));
|
||||
_timeScale = 1;
|
||||
|
||||
_state = spAnimationState_create(spAnimationStateData_create(_skeleton->data));
|
||||
_state->rendererObject = self;
|
||||
_state->listener = animationCallback;
|
||||
|
||||
@ -103,7 +106,7 @@ void disposeTrackEntry (spTrackEntry* entry) {
|
||||
stateInternal->disposeTrackEntry = disposeTrackEntry;
|
||||
}
|
||||
|
||||
- (id) initWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
|
||||
- (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
|
||||
self = [super initWithData:skeletonData ownsSkeletonData:ownsSkeletonData];
|
||||
if (!self) return nil;
|
||||
|
||||
@ -112,7 +115,7 @@ void disposeTrackEntry (spTrackEntry* entry) {
|
||||
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];
|
||||
if (!self) return nil;
|
||||
|
||||
@ -131,8 +134,8 @@ void disposeTrackEntry (spTrackEntry* entry) {
|
||||
}
|
||||
|
||||
- (void) dealloc {
|
||||
if (_ownsAnimationStateData) AnimationStateData_dispose(_state->data);
|
||||
AnimationState_dispose(_state);
|
||||
if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data);
|
||||
spAnimationState_dispose(_state);
|
||||
|
||||
[_startListener release];
|
||||
[_endListener release];
|
||||
@ -143,61 +146,60 @@ void disposeTrackEntry (spTrackEntry* entry) {
|
||||
}
|
||||
|
||||
- (void) update:(ccTime)deltaTime {
|
||||
[super update:deltaTime];
|
||||
|
||||
deltaTime *= _timeScale;
|
||||
AnimationState_update(_state, deltaTime);
|
||||
AnimationState_apply(_state, _skeleton);
|
||||
Skeleton_updateWorldTransform(_skeleton);
|
||||
spSkeleton_update(_skeleton, deltaTime);
|
||||
spAnimationState_update(_state, deltaTime);
|
||||
spAnimationState_apply(_state, _skeleton);
|
||||
spSkeleton_updateWorldTransform(_skeleton);
|
||||
}
|
||||
|
||||
- (void) setAnimationStateData:(AnimationStateData*)stateData {
|
||||
- (void) setAnimationStateData:(spAnimationStateData*)stateData {
|
||||
NSAssert(stateData, @"stateData cannot be null.");
|
||||
|
||||
if (_ownsAnimationStateData) AnimationStateData_dispose(_state->data);
|
||||
AnimationState_dispose(_state);
|
||||
if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data);
|
||||
spAnimationState_dispose(_state);
|
||||
|
||||
_ownsAnimationStateData = false;
|
||||
_state = AnimationState_create(stateData);
|
||||
_state = spAnimationState_create(stateData);
|
||||
_state->rendererObject = self;
|
||||
_state->listener = animationCallback;
|
||||
}
|
||||
|
||||
- (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 {
|
||||
Animation* animation = SkeletonData_findAnimation(_skeleton->data, [name UTF8String]);
|
||||
- (spTrackEntry*) setAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop {
|
||||
spAnimation* animation = spSkeletonData_findAnimation(_skeleton->data, [name UTF8String]);
|
||||
if (!animation) {
|
||||
CCLOG(@"Spine: Animation not found: %@", name);
|
||||
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 {
|
||||
Animation* animation = SkeletonData_findAnimation(_skeleton->data, [name UTF8String]);
|
||||
- (spTrackEntry*) addAnimationForTrack:(int)trackIndex name:(NSString*)name loop:(bool)loop afterDelay:(int)delay {
|
||||
spAnimation* animation = spSkeletonData_findAnimation(_skeleton->data, [name UTF8String]);
|
||||
if (!animation) {
|
||||
CCLOG(@"Spine: Animation not found: %@", name);
|
||||
return 0;
|
||||
}
|
||||
return AnimationState_addAnimation(_state, trackIndex, animation, loop, delay);
|
||||
return spAnimationState_addAnimation(_state, trackIndex, animation, loop, delay);
|
||||
}
|
||||
|
||||
- (TrackEntry*) getCurrentForTrack:(int)trackIndex {
|
||||
return AnimationState_getCurrent(_state, trackIndex);
|
||||
- (spTrackEntry*) getCurrentForTrack:(int)trackIndex {
|
||||
return spAnimationState_getCurrent(_state, trackIndex);
|
||||
}
|
||||
|
||||
- (void) clearTracks {
|
||||
AnimationState_clearTracks(_state);
|
||||
spAnimationState_clearTracks(_state);
|
||||
}
|
||||
|
||||
- (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) {
|
||||
case SP_ANIMATION_START:
|
||||
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);
|
||||
if (!entry->rendererObject) return;
|
||||
_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];
|
||||
}
|
||||
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onEnd:(EndListener)listener {
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onEnd:(spEndListener)listener {
|
||||
getListeners(entry)->endListener = [listener copy];
|
||||
}
|
||||
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onComplete:(CompleteListener)listener {
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onComplete:(spCompleteListener)listener {
|
||||
getListeners(entry)->completeListener = [listener copy];
|
||||
}
|
||||
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onEvent:(EventListener)listener {
|
||||
- (void) setListenerForEntry:(spTrackEntry*)entry onEvent:(spEventListener)listener {
|
||||
getListeners(entry)->eventListener = [listener copy];
|
||||
}
|
||||
|
||||
|
||||
@ -28,39 +28,37 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#define SPINE_SHORT_NAMES
|
||||
#import <spine/spine.h>
|
||||
#import "cocos2d.h"
|
||||
|
||||
@class PolygonBatch;
|
||||
@class spPolygonBatch;
|
||||
|
||||
/** Draws a skeleton. */
|
||||
@interface SkeletonRenderer : CCNodeRGBA<CCBlendProtocol> {
|
||||
Skeleton* _skeleton;
|
||||
Bone* _rootBone;
|
||||
float _timeScale;
|
||||
spSkeleton* _skeleton;
|
||||
spBone* _rootBone;
|
||||
bool _debugSlots;
|
||||
bool _debugBones;
|
||||
bool _premultipliedAlpha;
|
||||
ccBlendFunc _blendFunc;
|
||||
|
||||
bool _ownsSkeletonData;
|
||||
Atlas* _atlas;
|
||||
PolygonBatch* batch;
|
||||
spAtlas* _atlas;
|
||||
spPolygonBatch* batch;
|
||||
float* worldVertices;
|
||||
}
|
||||
|
||||
+ (id) skeletonWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale;
|
||||
+ (id) skeletonWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale;
|
||||
+ (id) skeletonWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale;
|
||||
|
||||
- (id) initWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale;
|
||||
- (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale;
|
||||
- (id) initWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale;
|
||||
|
||||
- (CCTexture2D*) getTextureForRegion:(RegionAttachment*)attachment;
|
||||
- (CCTexture2D*) getTextureForMesh:(MeshAttachment*)attachment;
|
||||
- (CCTexture2D*) getTextureForSkinnedMesh:(SkinnedMeshAttachment*)attachment;
|
||||
- (CCTexture2D*) getTextureForRegion:(spRegionAttachment*)attachment;
|
||||
- (CCTexture2D*) getTextureForMesh:(spMeshAttachment*)attachment;
|
||||
- (CCTexture2D*) getTextureForSkinnedMesh:(spSkinnedMeshAttachment*)attachment;
|
||||
|
||||
// --- Convenience methods for common Skeleton_* functions.
|
||||
- (void) updateWorldTransform;
|
||||
@ -70,10 +68,10 @@
|
||||
- (void) setSlotsToSetupPose;
|
||||
|
||||
/* Returns 0 if the bone was not found. */
|
||||
- (Bone*) findBone:(NSString*)boneName;
|
||||
- (spBone*) findBone:(NSString*)boneName;
|
||||
|
||||
/* 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
|
||||
* 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;
|
||||
|
||||
/* 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. */
|
||||
- (bool) setAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName;
|
||||
|
||||
@property (nonatomic, readonly) Skeleton* skeleton;
|
||||
@property (nonatomic) float timeScale;
|
||||
@property (nonatomic, readonly) spSkeleton* skeleton;
|
||||
@property (nonatomic) bool debugSlots;
|
||||
@property (nonatomic) bool debugBones;
|
||||
@property (nonatomic) Bone* rootBone;
|
||||
@property (nonatomic) spBone* rootBone;
|
||||
|
||||
@end
|
||||
|
||||
@ -36,22 +36,21 @@
|
||||
static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
|
||||
@interface SkeletonRenderer (Private)
|
||||
- (void) initialize:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
- (void) initialize:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData;
|
||||
@end
|
||||
|
||||
@implementation SkeletonRenderer
|
||||
|
||||
@synthesize skeleton = _skeleton;
|
||||
@synthesize rootBone = _rootBone;
|
||||
@synthesize timeScale = _timeScale;
|
||||
@synthesize debugSlots = _debugSlots;
|
||||
@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];
|
||||
}
|
||||
|
||||
+ (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];
|
||||
}
|
||||
|
||||
@ -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];
|
||||
}
|
||||
|
||||
- (void) initialize:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
|
||||
- (void) initialize:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
|
||||
_ownsSkeletonData = ownsSkeletonData;
|
||||
|
||||
_timeScale = 1;
|
||||
|
||||
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];
|
||||
|
||||
_blendFunc.src = GL_ONE;
|
||||
@ -79,7 +76,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
[self scheduleUpdate];
|
||||
}
|
||||
|
||||
- (id) initWithData:(SkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
|
||||
- (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
|
||||
NSAssert(skeletonData, @"skeletonData cannot be null.");
|
||||
|
||||
self = [super init];
|
||||
@ -90,15 +87,15 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
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];
|
||||
if (!self) return nil;
|
||||
|
||||
SkeletonJson* json = SkeletonJson_create(atlas);
|
||||
json->scale = scale == 0 ? (1 / CC_CONTENT_SCALE_FACTOR()) : scale;
|
||||
SkeletonData* skeletonData = SkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
|
||||
spSkeletonJson* json = spSkeletonJson_create(atlas);
|
||||
json->scale = scale / CC_CONTENT_SCALE_FACTOR();
|
||||
spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
|
||||
NSAssert(skeletonData, ([NSString stringWithFormat:@"Error reading skeleton data file: %@\nError: %s", skeletonDataFile, json->error]));
|
||||
SkeletonJson_dispose(json);
|
||||
spSkeletonJson_dispose(json);
|
||||
if (!skeletonData) return 0;
|
||||
|
||||
[self initialize:skeletonData ownsSkeletonData:YES];
|
||||
@ -110,15 +107,15 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
self = [super init];
|
||||
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]));
|
||||
if (!_atlas) return 0;
|
||||
|
||||
SkeletonJson* json = SkeletonJson_create(_atlas);
|
||||
json->scale = scale == 0 ? (1 / CC_CONTENT_SCALE_FACTOR()) : scale;
|
||||
SkeletonData* skeletonData = SkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
|
||||
spSkeletonJson* json = spSkeletonJson_create(_atlas);
|
||||
json->scale = scale / CC_CONTENT_SCALE_FACTOR();
|
||||
spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
|
||||
NSAssert(skeletonData, ([NSString stringWithFormat:@"Error reading skeleton data file: %@\nError: %s", skeletonDataFile, json->error]));
|
||||
SkeletonJson_dispose(json);
|
||||
spSkeletonJson_dispose(json);
|
||||
if (!skeletonData) return 0;
|
||||
|
||||
[self initialize:skeletonData ownsSkeletonData:YES];
|
||||
@ -127,18 +124,14 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
}
|
||||
|
||||
- (void) dealloc {
|
||||
if (_ownsSkeletonData) SkeletonData_dispose(_skeleton->data);
|
||||
if (_atlas) Atlas_dispose(_atlas);
|
||||
Skeleton_dispose(_skeleton);
|
||||
if (_ownsSkeletonData) spSkeletonData_dispose(_skeleton->data);
|
||||
if (_atlas) spAtlas_dispose(_atlas);
|
||||
spSkeleton_dispose(_skeleton);
|
||||
[batch release];
|
||||
FREE(worldVertices);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) update:(ccTime)deltaTime {
|
||||
Skeleton_update(_skeleton, deltaTime * _timeScale);
|
||||
}
|
||||
|
||||
- (void) draw {
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
@ -156,7 +149,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
int trianglesCount = 0;
|
||||
float r = 0, g = 0, b = 0, a = 0;
|
||||
for (int i = 0, n = _skeleton->slotCount; i < n; i++) {
|
||||
Slot* slot = _skeleton->drawOrder[i];
|
||||
spSlot* slot = _skeleton->drawOrder[i];
|
||||
if (!slot->attachment) continue;
|
||||
CCTexture2D *texture = 0;
|
||||
switch (slot->attachment->type) {
|
||||
@ -227,9 +220,9 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
glLineWidth(1);
|
||||
CGPoint points[4];
|
||||
for (int i = 0, n = _skeleton->slotCount; i < n; i++) {
|
||||
Slot* slot = _skeleton->drawOrder[i];
|
||||
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
|
||||
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
|
||||
spSlot* slot = _skeleton->drawOrder[i];
|
||||
if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
|
||||
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
||||
spRegionAttachment_computeWorldVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, worldVertices);
|
||||
points[0] = ccp(worldVertices[0], worldVertices[1]);
|
||||
points[1] = ccp(worldVertices[2], worldVertices[3]);
|
||||
@ -243,7 +236,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
glLineWidth(2);
|
||||
ccDrawColor4B(255, 0, 0, 255);
|
||||
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 y = bone->data->length * bone->m10 + bone->worldY;
|
||||
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);
|
||||
ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
|
||||
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));
|
||||
if (i == 0) ccDrawColor4B(0, 255, 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (CCTexture2D*) getTextureForRegion:(RegionAttachment*)attachment {
|
||||
return (CCTexture2D*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject;
|
||||
- (CCTexture2D*) getTextureForRegion:(spRegionAttachment*)attachment {
|
||||
return (CCTexture2D*)((spAtlasRegion*)attachment->rendererObject)->page->rendererObject;
|
||||
}
|
||||
|
||||
- (CCTexture2D*) getTextureForMesh:(MeshAttachment*)attachment {
|
||||
return (CCTexture2D*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject;
|
||||
- (CCTexture2D*) getTextureForMesh:(spMeshAttachment*)attachment {
|
||||
return (CCTexture2D*)((spAtlasRegion*)attachment->rendererObject)->page->rendererObject;
|
||||
}
|
||||
|
||||
- (CCTexture2D*) getTextureForSkinnedMesh:(SkinnedMeshAttachment*)attachment {
|
||||
return (CCTexture2D*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject;
|
||||
- (CCTexture2D*) getTextureForSkinnedMesh:(spSkinnedMeshAttachment*)attachment {
|
||||
return (CCTexture2D*)((spAtlasRegion*)attachment->rendererObject)->page->rendererObject;
|
||||
}
|
||||
|
||||
- (CGRect) boundingBox {
|
||||
@ -277,26 +270,26 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||
float scaleY = self.scaleY;
|
||||
float vertices[8];
|
||||
for (int i = 0; i < _skeleton->slotCount; ++i) {
|
||||
Slot* slot = _skeleton->slots[i];
|
||||
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
|
||||
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
|
||||
RegionAttachment_computeWorldVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices);
|
||||
minX = fmin(minX, vertices[VERTEX_X1] * scaleX);
|
||||
minY = fmin(minY, vertices[VERTEX_Y1] * scaleY);
|
||||
maxX = fmax(maxX, vertices[VERTEX_X1] * scaleX);
|
||||
maxY = fmax(maxY, vertices[VERTEX_Y1] * scaleY);
|
||||
minX = fmin(minX, vertices[VERTEX_X4] * scaleX);
|
||||
minY = fmin(minY, vertices[VERTEX_Y4] * scaleY);
|
||||
maxX = fmax(maxX, vertices[VERTEX_X4] * scaleX);
|
||||
maxY = fmax(maxY, vertices[VERTEX_Y4] * scaleY);
|
||||
minX = fmin(minX, vertices[VERTEX_X2] * scaleX);
|
||||
minY = fmin(minY, vertices[VERTEX_Y2] * scaleY);
|
||||
maxX = fmax(maxX, vertices[VERTEX_X2] * scaleX);
|
||||
maxY = fmax(maxY, vertices[VERTEX_Y2] * scaleY);
|
||||
minX = fmin(minX, vertices[VERTEX_X3] * scaleX);
|
||||
minY = fmin(minY, vertices[VERTEX_Y3] * scaleY);
|
||||
maxX = fmax(maxX, vertices[VERTEX_X3] * scaleX);
|
||||
maxY = fmax(maxY, vertices[VERTEX_Y3] * scaleY);
|
||||
spSlot* slot = _skeleton->slots[i];
|
||||
if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
|
||||
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
||||
spRegionAttachment_computeWorldVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices);
|
||||
minX = fmin(minX, vertices[SP_VERTEX_X1] * scaleX);
|
||||
minY = fmin(minY, vertices[SP_VERTEX_Y1] * scaleY);
|
||||
maxX = fmax(maxX, vertices[SP_VERTEX_X1] * scaleX);
|
||||
maxY = fmax(maxY, vertices[SP_VERTEX_Y1] * scaleY);
|
||||
minX = fmin(minX, vertices[SP_VERTEX_X4] * scaleX);
|
||||
minY = fmin(minY, vertices[SP_VERTEX_Y4] * scaleY);
|
||||
maxX = fmax(maxX, vertices[SP_VERTEX_X4] * scaleX);
|
||||
maxY = fmax(maxY, vertices[SP_VERTEX_Y4] * scaleY);
|
||||
minX = fmin(minX, vertices[SP_VERTEX_X2] * scaleX);
|
||||
minY = fmin(minY, vertices[SP_VERTEX_Y2] * scaleY);
|
||||
maxX = fmax(maxX, vertices[SP_VERTEX_X2] * scaleX);
|
||||
maxY = fmax(maxY, vertices[SP_VERTEX_Y2] * scaleY);
|
||||
minX = fmin(minX, vertices[SP_VERTEX_X3] * scaleX);
|
||||
minY = fmin(minY, vertices[SP_VERTEX_Y3] * scaleY);
|
||||
maxX = fmax(maxX, vertices[SP_VERTEX_X3] * scaleX);
|
||||
maxY = fmax(maxY, vertices[SP_VERTEX_Y3] * scaleY);
|
||||
}
|
||||
minX = self.position.x + minX;
|
||||
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.
|
||||
|
||||
- (void) updateWorldTransform {
|
||||
Skeleton_updateWorldTransform(_skeleton);
|
||||
spSkeleton_updateWorldTransform(_skeleton);
|
||||
}
|
||||
|
||||
- (void) setToSetupPose {
|
||||
Skeleton_setToSetupPose(_skeleton);
|
||||
spSkeleton_setToSetupPose(_skeleton);
|
||||
}
|
||||
- (void) setBonesToSetupPose {
|
||||
Skeleton_setBonesToSetupPose(_skeleton);
|
||||
spSkeleton_setBonesToSetupPose(_skeleton);
|
||||
}
|
||||
- (void) setSlotsToSetupPose {
|
||||
Skeleton_setSlotsToSetupPose(_skeleton);
|
||||
spSkeleton_setSlotsToSetupPose(_skeleton);
|
||||
}
|
||||
|
||||
- (Bone*) findBone:(NSString*)boneName {
|
||||
return Skeleton_findBone(_skeleton, [boneName UTF8String]);
|
||||
- (spBone*) findBone:(NSString*)boneName {
|
||||
return spSkeleton_findBone(_skeleton, [boneName UTF8String]);
|
||||
}
|
||||
|
||||
- (Slot*) findSlot:(NSString*)slotName {
|
||||
return Skeleton_findSlot(_skeleton, [slotName UTF8String]);
|
||||
- (spSlot*) findSlot:(NSString*)slotName {
|
||||
return spSkeleton_findSlot(_skeleton, [slotName UTF8String]);
|
||||
}
|
||||
|
||||
- (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 {
|
||||
return Skeleton_getAttachmentForSlotName(_skeleton, [slotName UTF8String], [attachmentName UTF8String]);
|
||||
- (spAttachment*) getAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName {
|
||||
return spSkeleton_getAttachmentForSlotName(_skeleton, [slotName UTF8String], [attachmentName UTF8String]);
|
||||
}
|
||||
- (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
|
||||
|
||||
@ -28,7 +28,6 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#define SPINE_SHORT_NAMES
|
||||
#import <spine/spine.h>
|
||||
#import "cocos2d.h"
|
||||
#import <spine/SkeletonRenderer.h>
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
#import <spine/spine-cocos2d-iphone.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];
|
||||
self->rendererObject = texture;
|
||||
CGSize size = texture.contentSizeInPixels;
|
||||
@ -39,10 +39,10 @@ void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
|
||||
self->height = size.height;
|
||||
}
|
||||
|
||||
void _AtlasPage_disposeTexture (AtlasPage* self) {
|
||||
void _spAtlasPage_disposeTexture (spAtlasPage* self) {
|
||||
[(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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user