mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-15 11:31:37 +08:00
Brought back some convenience methods.
Anything more than this and you have to use the C API!
This commit is contained in:
parent
b73132f910
commit
9cadc92b97
@ -35,6 +35,7 @@ Draws a skeleton.
|
||||
*/
|
||||
@interface CCSkeleton : CCNodeRGBA<CCBlendProtocol> {
|
||||
Skeleton* _skeleton;
|
||||
Bone* _rootBone;
|
||||
float _timeScale;
|
||||
bool _debugSlots;
|
||||
bool _debugBones;
|
||||
@ -52,9 +53,33 @@ Draws a skeleton.
|
||||
- (id) initWithFile:(NSString*)skeletonDataFile atlas:(Atlas*)atlas scale:(float)scale;
|
||||
- (id) initWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale;
|
||||
|
||||
// --- Convenience methods for common Skeleton_* functions.
|
||||
- (void) updateWorldTransform;
|
||||
|
||||
- (void) setToBindPose;
|
||||
- (void) setBonesToBindPose;
|
||||
- (void) setSlotsToBindPose;
|
||||
|
||||
/* Returns 0 if the bone was not found. */
|
||||
- (Bone*) findBone:(NSString*)boneName;
|
||||
|
||||
/* Returns 0 if the slot was not found. */
|
||||
- (Slot*) 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. Returns false if the skin was not found.
|
||||
* @param skin May be 0.*/
|
||||
- (bool) setSkin:(NSString*)skinName;
|
||||
|
||||
/* Returns 0 if the slot or attachment was not found. */
|
||||
- (Attachment*) 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) bool debugSlots;
|
||||
@property (nonatomic) bool debugBones;
|
||||
@property (nonatomic) Bone* rootBone;
|
||||
|
||||
@end
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
@implementation CCSkeleton
|
||||
|
||||
@synthesize skeleton = _skeleton;
|
||||
@synthesize rootBone = _rootBone;
|
||||
@synthesize timeScale = _timeScale;
|
||||
@synthesize debugSlots = _debugSlots;
|
||||
@synthesize debugBones = _debugBones;
|
||||
@ -53,6 +54,7 @@
|
||||
_ownsSkeletonData = ownsSkeletonData;
|
||||
|
||||
_skeleton = Skeleton_create(skeletonData);
|
||||
_rootBone = _skeleton->bones[0];
|
||||
|
||||
_blendFunc.src = GL_ONE;
|
||||
_blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
||||
@ -232,7 +234,42 @@
|
||||
return CGRectMake(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
// CCBlendProtocol
|
||||
// --- Convenience methods for Skeleton_* functions.
|
||||
|
||||
- (void) updateWorldTransform {
|
||||
Skeleton_updateWorldTransform(_skeleton);
|
||||
}
|
||||
|
||||
- (void) setToBindPose {
|
||||
Skeleton_setToBindPose(_skeleton);
|
||||
}
|
||||
- (void) setBonesToBindPose {
|
||||
Skeleton_setBonesToBindPose(_skeleton);
|
||||
}
|
||||
- (void) setSlotsToBindPose {
|
||||
Skeleton_setSlotsToBindPose(_skeleton);
|
||||
}
|
||||
|
||||
- (Bone*) findBone:(NSString*)boneName {
|
||||
return Skeleton_findBone(_skeleton, [boneName UTF8String]);
|
||||
}
|
||||
|
||||
- (Slot*) findSlot:(NSString*)slotName {
|
||||
return Skeleton_findSlot(_skeleton, [slotName UTF8String]);
|
||||
}
|
||||
|
||||
- (bool) setSkin:(NSString*)skinName {
|
||||
return (bool)Skeleton_setSkinByName(_skeleton, skinName ? [skinName UTF8String] : 0);
|
||||
}
|
||||
|
||||
- (Attachment*) getAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName {
|
||||
return Skeleton_getAttachmentForSlotName(_skeleton, [slotName UTF8String], [attachmentName UTF8String]);
|
||||
}
|
||||
- (bool) setAttachment:(NSString*)slotName attachmentName:(NSString*)attachmentName {
|
||||
return (bool)Skeleton_setAttachment(_skeleton, [slotName UTF8String], [attachmentName UTF8String]);
|
||||
}
|
||||
|
||||
// --- CCBlendProtocol
|
||||
|
||||
- (void) setBlendFunc:(ccBlendFunc)func {
|
||||
self.blendFunc = func;
|
||||
|
||||
@ -64,6 +64,7 @@ void CCSkeleton::initialize () {
|
||||
|
||||
void CCSkeleton::setSkeletonData (SkeletonData *skeletonData, bool ownsSkeletonData) {
|
||||
skeleton = Skeleton_create(skeletonData);
|
||||
rootBone = skeleton->bones[0];
|
||||
this->ownsSkeletonData = ownsSkeletonData;
|
||||
}
|
||||
|
||||
@ -222,7 +223,42 @@ CCRect CCSkeleton::boundingBox () {
|
||||
return CCRectMake(position.x + minX, position.y + minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
// CCBlendProtocol
|
||||
// --- Convenience methods for Skeleton_* functions.
|
||||
|
||||
void CCSkeleton::updateWorldTransform () {
|
||||
Skeleton_updateWorldTransform(skeleton);
|
||||
}
|
||||
|
||||
void CCSkeleton::setToBindPose () {
|
||||
Skeleton_setToBindPose(skeleton);
|
||||
}
|
||||
void CCSkeleton::setBonesToBindPose () {
|
||||
Skeleton_setBonesToBindPose(skeleton);
|
||||
}
|
||||
void CCSkeleton::setSlotsToBindPose () {
|
||||
Skeleton_setSlotsToBindPose(skeleton);
|
||||
}
|
||||
|
||||
Bone* CCSkeleton::findBone (const char* boneName) const {
|
||||
return Skeleton_findBone(skeleton, boneName);
|
||||
}
|
||||
|
||||
Slot* CCSkeleton::findSlot (const char* slotName) const {
|
||||
return Skeleton_findSlot(skeleton, slotName);
|
||||
}
|
||||
|
||||
bool CCSkeleton::setSkin (const char* skinName) {
|
||||
return Skeleton_setSkinByName(skeleton, skinName) ? true : false;
|
||||
}
|
||||
|
||||
Attachment* CCSkeleton::getAttachment (const char* slotName, const char* attachmentName) const {
|
||||
return Skeleton_getAttachmentForSlotName(skeleton, slotName, attachmentName);
|
||||
}
|
||||
bool CCSkeleton::setAttachment (const char* slotName, const char* attachmentName) {
|
||||
return Skeleton_setAttachment(skeleton, slotName, attachmentName) ? true : false;
|
||||
}
|
||||
|
||||
// --- CCBlendProtocol
|
||||
|
||||
ccBlendFunc CCSkeleton::getBlendFunc () {
|
||||
return blendFunc;
|
||||
|
||||
@ -37,6 +37,7 @@ Draws a skeleton.
|
||||
class CCSkeleton: public cocos2d::CCNodeRGBA, public cocos2d::CCBlendProtocol {
|
||||
public:
|
||||
Skeleton* skeleton;
|
||||
Bone* rootBone;
|
||||
float timeScale;
|
||||
bool debugSlots;
|
||||
bool debugBones;
|
||||
@ -55,7 +56,29 @@ public:
|
||||
virtual void draw ();
|
||||
virtual cocos2d::CCRect boundingBox ();
|
||||
|
||||
// CCBlendProtocol
|
||||
// --- Convenience methods for common Skeleton_* functions.
|
||||
void updateWorldTransform ();
|
||||
|
||||
void setToBindPose ();
|
||||
void setBonesToBindPose ();
|
||||
void setSlotsToBindPose ();
|
||||
|
||||
/* Returns 0 if the bone was not found. */
|
||||
Bone* findBone (const char* boneName) const;
|
||||
/* Returns 0 if the slot was not found. */
|
||||
Slot* findSlot (const char* slotName) const;
|
||||
|
||||
/* 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. Returns false if the skin was not found.
|
||||
* @param skin May be 0.*/
|
||||
bool setSkin (const char* skinName);
|
||||
|
||||
/* Returns 0 if the slot or attachment was not found. */
|
||||
Attachment* getAttachment (const char* slotName, const char* attachmentName) const;
|
||||
/* Returns false if the slot or attachment was not found. */
|
||||
bool setAttachment (const char* slotName, const char* attachmentName);
|
||||
|
||||
// --- CCBlendProtocol
|
||||
CC_PROPERTY(cocos2d::ccBlendFunc, blendFunc, BlendFunc);
|
||||
|
||||
protected:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user