2012-04-09 2 views
1

나는적인 Cocos2D 1.01로 ABC 오픈 소스와 회전 소스 코드를 다운로드 한. 는 지금은 초기화 스프라이트 서브 클래스에 문제가 있어요. (내 서브 클래스는 OrbSprite @interface입니다 : CCSprite)CCApprite 하위 클래스에서 self.addChild를 호출하면 iPhone 앱이 다운 됨

이 코드는 무한 루프 이상적인 Cocos2D 버전입니다.

-(id) init { 
self = [super init]; 

if (self) 
{ 
    [self initWithFile:@"bubble1.png"]; 
    Animation *bub = [Animation animationWithName:@"bubble" delay:0 images:@"bubble1.png", @"bubble2.png", nil]; 
    self.bubble = bub; 
    [bub release]; 

    [self addAnimation:bubble]; 

    Label *l = [[Label alloc] initWithString:@"" dimensions:CGSizeMake(45, 45) alignment:UITextAlignmentCenter 
          fontName:@"Arial Rounded MT Bold" fontSize:18]; 
    self.label = l; 
    [l release]; 

} 

return self; } 

I 솔루션의 검색과는 init 메소드의 이름을 변경하여 해결할 수 있습니다.

-(id) initWithBubbleImage { 

if ((self = [super initWithFile :@"bubble1.png"])) 
{ 
    NSLog(@"OrbSprite init in if self Method"); 

    bubblea = [NSArray arrayWithObjects:@"bubble1.png",@"bubble2.png",nil]; 

bub = [CCAnimation animationWithFrames:bubblea delay:0 ]; 
    [[CCAnimationCache sharedAnimationCache] addAnimation:bub name:@"bubbleAnim"]; 
    self.bubble = bub; 
    [bub release]; 

label = [[CCLabelTTF alloc] initWithString:@"" dimensions:CGSizeMake(45, 45) alignment:UITextAlignmentCenter 
       fontName:@"Arial Rounded MT Bold" fontSize:18]; 
} 
return self; } 

???? 하는 AddChild 동일한 서브 클래스에서 오류였다 디버그 지역에 .. "* * 어설 션 실패 - [-"(있는 NSString ) STR (무효) setLabelStr는 "문제는 변화 초기화 이름이 이미, 내가에서 발견했을 때이다 OrbSprite하는 AddChild :이이

- (void) setLabelStr:(NSString *) str { 
[label setString:str]; 
[self addChild:label]; 
[label setAnchorPoint:ccp(0, 13)]; } 

아무도 나를 도와 줘요 같은 서브 클래스의 방법이다

" '인수 nil이 아닌 있어야합니다']"와 "이유는, 때문에 캐치되지 않는 예외 'NSInternalInconsistencyException'응용 프로그램 종료. ...... 고맙습니다.

============================================== =======================

편집 - 편집 - 편집 - 편집 - 편집 - 나는했습니다

편집 답장으로이 작업을 수행하십시오. 하지만 여전히 들으의 작동하지 않습니다이 .H와하는 .m 코드를입니다

OrbSprite.h

이 코드

입니다
#import "cocos2d.h" 
@interface OrbSprite : CCSprite 
{ 
CCLabelTTF *label; 
CCAnimation *bubble; 
BOOL isBubble; 
BOOL isHidden; 
int order; 

CCSequence *popSequence; 
} 
@property (nonatomic, retain) CCLabelTTF *label; 
@property (nonatomic, retain) CCSequence *popSequence; 
@property (nonatomic, retain) CCAnimation *bubble; 
@property (nonatomic, retain) NSArray *bubblea; 
@property (readwrite) BOOL isBubble; 
@property (readwrite) BOOL isHidden; 
@property (readwrite) int order; 
-(id)initWithBubbleImage; 
- (void) pop; 
- (void) setLabelStr:(NSString *) str; 
- (void) showBubble; 
- (void) reset; 
@end 

OrbSprite.m

,

는 또한 같은 문제가

입니다 발견 .. 코드

#import "OrbSprite.h" 
@implementation OrbSprite 
@synthesize bubble; 
@synthesize label; 
@synthesize isBubble; 
@synthesize isHidden; 
@synthesize popSequence; 
@synthesize order; 
@synthesize bubblea; 

-(id) initWithBubbleImage { 

if ((self = [super initWithFile:@"bubble1.png"])) 
{ 

    bubblea = [NSArray arrayWithObjects:@"bubble1.png",@"bubble2.png",nil]; 

    bubble= [CCAnimation animationWithFrames:bubblea delay:0 ]; 
    [[CCAnimationCache sharedAnimationCache] addAnimation:bub name:@"bubbleAnim"]; 

    label = [[CCLabelTTF alloc] initWithString:@"" dimensions:CGSizeMake(45, 45) 
    alignment:UITextAlignmentCenter fontName:@"Arial Rounded MT Bold" fontSize:18]; 
    } 
return self; 
} 

- (void) pop { 
isBubble = NO; 
popSequence = [CCSequence actions:[CCScaleTo actionWithDuration:.1 scale:.5], 
    [CCScaleTo actionWithDuration:.1 scale:2], [CCCallFunc actionWithTarget:self 
    selector:@selector(finishedPopSequence)], nil]; 
[self runAction:popSequence]; 
} 

- (void) finishedPopSequence { 
self.scale = 1; 
[self setDisplayFrameWithAnimationName:@"bubble" index:0]; } 

- (void) reset { 
self.scale = 1; 
[self setDisplayFrameWithAnimationName:@"bubble" index:0]; } 

- (void)showBubble { 
    isBubble = YES; 
    [self removeChild:label cleanup:NO]; 
    [self setDisplayFrameWithAnimationName:@"bubbleAnim" index:1]; 
    self.scale = .5; 
    id Orbshowscale = [CCScaleTo actionWithDuration:1 scale:1.5]; 
    id Orbshowscale2= [CCScaleTo actionWithDuration:.1 scale:1]; 
    [self runAction:[CCSequence actions:Orbshowscale,Orbshowscale2 , nil]]; } 

- (void) setLabelStr:(NSString *) str { 
[label setString:str]; 
[self addChild:label]; //<<< *** Assertion failure in -[OrbSprite addChild:] 
[label setAnchorPoint:ccp(0, 13)]; } 

@end 

이미 과다 방출 문제 .. 를 해결하지만 여전히 작업 '말아입니다 *** 어설 실패 - [OrbSprite addChild :]

*** 캐치되지 않은 예외 'NSInternalInconsistencyException'으로 인해 앱 종료 중, 이유 : '인수가 0이 아니어야합니다'

친애하는 모든 분들께 감사드립니다.

+0

제거'[BUB 자료] 회신 에 대한' – tipycalFlow

+0

덕분에 내가 .. 제거하려고하지만 여전히 오류 ... 내가 무엇을해야 은 ... 당신에게 reply..Macro I 시도에 대한 – chgdev

답변

1

init 메소드에서 변수 "bub"를 과도하게 공개하는 것처럼 보입니다. alloc 또는 create 메소드 호출을 통해 생성하지 않으므로 릴리스하지 않아야합니다.

+0

감사 감사 삭제할 수 있습니다. 'bubblea = [NSArray arrayWithObjects : @ "bubble1.png", @ "bubble2.png", nil]; bub = [CCAnimation animationWithFrames : bubblea delay : 0]; [[CCAnimationCache sharedAnimationCache] addAnimation : 풍선 이름 : @ "bubbleAnim"]; self.bubble = bub; [bub release]; ' 또한 오류가있었습니다. 어떻게해야합니까? 감사합니다 .... – chgdev

+0

다시 한번, [bub release]를 제거하십시오. – Marco

0

bubself.bubble으로 할당 한 다음 bub을 출시했습니다. 둘 다 동일한 주소를 가리 킵니다. self.label에 대해서도 마찬가지입니다.

-(id) init { 
self = [super init]; 

if (self) 
{ 
[self initWithFile:@"bubble1.png"]; 
Animation *bub = [Animation animationWithName:@"bubble" delay:0 images:@"bubble1.png", @"bubble2.png", nil]; 
self.bubble = bub; 
//[bub release]; <-- This shouldn't be done 

[self addAnimation:bubble]; 

Label *l = [[Label alloc] initWithString:@"" dimensions:CGSizeMake(45, 45) alignment:UITextAlignmentCenter 
         fontName:@"Arial Rounded MT Bold" fontSize:18]; 
self.label = l; 
//[l release]; <-- This shouldn't be done 

} 
return self; } 

편집 -이 this-

[self addChild:self.label]; //<<< *** Assertion failure in -[OrbSprite addChild:] 
0

사용 ALLOC을 시도하고이 출시 된 이후 그것 : 그것은이 방법을 사용해보십시오.