정말 좋은 질문입니다 (마침내!).
내가 할 일은 독자적으로 움직일 수있는 다른 스프라이트 (이미 했음)로 캐릭터를 분리하는 것입니다.
그런 다음 해당 애니메이션의 프레임이 표시 될 때마다 무기 애니메이션의 위치를 수정 한 코드 블록을 실행하여 어깨와 일치시킵니다.
코드 블록을 실행하려면 CCAnimationFrame을 거기에 추가 했으므로 Cocos 1.1 이상이 필요합니다. 그러나 해당 프레임은 NSNotification을 통해 코드를 실행할 수 있기 때문에 블록을 설정할 수 있도록 개선했습니다. 해당 프레임이 표시 될 때마다 해당 블록이 실행됩니다.
그냥 CCAnimation.h을 찾아 같이하는 CCAnimationFrame 인터페이스를 수정
typedef void(^FrameBlock)(CCSprite *sprite);
/** CCAnimationFrame
A frame of the animation. It contains information like:
- sprite frame name
- # of delay units.
- offset
@since v1.1
*/
@interface CCAnimationFrame : NSObject <NSCopying>
{
CCSpriteFrame* spriteFrame_;
float delayUnits_;
NSDictionary *userInfo_;
FrameBlock frameBlock;
}
/** CCSpriteFrameName to be used */
@property (nonatomic, readwrite, retain) CCSpriteFrame* spriteFrame;
/** how many units of time the frame takes */
@property (nonatomic, readwrite) float delayUnits;
/** A CCAnimationFrameDisplayedNotification notification will be broadcasted when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcasted. */
@property (nonatomic, readwrite, retain) NSDictionary *userInfo;
/** If the block is not NULL, it will be executed when the frame becomes visible **/
@property (nonatomic, readwrite, copy) FrameBlock frameBlock;
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
-(id) initWithSpriteFrame:(CCSpriteFrame*)spriteFrame delayUnits:(float)delayUnits userInfo:(NSDictionary*)userInfo;
-(id) initWithSpriteFrame:(CCSpriteFrame*)spriteFrame delayUnits:(float)delayUnits block:(FrameBlock)block;
@end
을 다음 열기 CCAnimation.m과 CCAnimationFrame 구현은 다음과 같습니다 확인 : 다음
@implementation CCAnimationFrame
@synthesize spriteFrame = spriteFrame_, delayUnits = delayUnits_, userInfo=userInfo_;
@synthesize frameBlock;
-(id) initWithSpriteFrame:(CCSpriteFrame *)spriteFrame delayUnits:(float)delayUnits userInfo:(NSDictionary*)userInfo
{
if((self=[super init])) {
self.spriteFrame = spriteFrame;
self.delayUnits = delayUnits;
self.userInfo = userInfo;
}
return self;
}
-(id) initWithSpriteFrame:(CCSpriteFrame*)spriteFrame delayUnits:(float)delayUnits block:(FrameBlock)block{
self = [self initWithSpriteFrame:spriteFrame delayUnits:delayUnits userInfo:nil];
if(self){
[self setFrameBlock:block];
}
return self;
}
-(void) dealloc
{
CCLOGINFO(@"cocos2d: deallocing %@", self);
[spriteFrame_ release];
[userInfo_ release];
[super dealloc];
}
-(id) copyWithZone: (NSZone*) zone
{
CCAnimationFrame *copy = [[[self class] allocWithZone: zone] initWithSpriteFrame:[[spriteFrame_ copy] autorelease] delayUnits:delayUnits_ userInfo:[[userInfo_ copy] autorelease] ];
return copy;
}
-(NSString*) description
{
return [NSString stringWithFormat:@"<%@ = %08X | SpriteFrame = %08X, delayUnits = %0.2f >", [self class], self, spriteFrame_, delayUnits_ ];
}
@end
, 애니메이션 프레임을 생성 할 때, 팔의 위치를 설정하여 어깨와 일치시키는 블록을 추가하십시오.
도움이되기를 바랍니다.
로봇은 스프라이트 시트 여야합니다. –