2012-09-19 2 views
0

내 메인 레이어의 스코어를 내 스코어에 따라 초기화하는 CCSprite 중 하나로 전달하려고합니다. 내 CCSprite 초기화 할 때 :Cocos2d의 오브젝트로 CCSprite 초기화하기

//Main Layer 
Platform *platform = [[Platform alloc] initWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:@"platform.png"] withScore:score]; 

//CCSprite Layer 
-(id) initWithSpriteFrame:(CCSpriteFrame*)spriteFrame withScore:(int)initScore { 
    if((self=[super init])) { 
    ... 
    } 
} 

나는 CCSprite 질감이없는 점수를 얻습니다. 그 후

, 나는이 함께 초기화 :

//Main Layer 
Platform *platform = [[Platform alloc]initWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:@"platform.png"]]; 
[platform setScore:score]; 

//CCSprite Layer 
@property (readwrite) int score; 
@synthesize score; 

-(id) init { 
    if((self=[super init])) { 
    ... 
    } 
} 

나는 어떤 점수 (는 0이다)와 CCSprite 텍스처를 얻을. 할 사람이 뭐야?

답변

0

첫 번째 코드 예에서 스프라이트 프레임을 슈퍼로 전달해야 변경 될 수 있습니다.

//CCSprite Layer 
-(id) initWithSpriteFrame:(CCSpriteFrame*)spriteFrame withScore:(int)initScore { 
    if((self=[super initWithSpriteFrame:spriteFrame])) { 
     ... 
    } 

    return self; //Make sure to return self! 
} 
+0

감사합니다. 완벽하게 작동합니다. –