2013-05-30 3 views
1

자체 클래스에 "폭탄"CCSprite이 있습니다 (cocos2d를 사용하지 않는 사람들이 이것을 읽으면 CCSprite는 NSObject입니다). 내가 .H에서 @class Bomb;와 (프로처럼 HelloWorldLayer) 내 게임 층에 추가MutableArray 크래시에 CCSprite (NSObject) 추가하기

Bomb.h: 
#import <Foundation/Foundation.h> 
#import "cocos2d.h" 
#import <OpenAL/al.h> 

@class HelloWorldLayer; 

@interface Bomb : CCSprite { 
    @private 
    int length; 


} 
@property (readwrite) int length; 

@end 



Bomb.m: 
#import "Bomb.h" 


@implementation Bomb 
@synthesize length = _length; 

@end 

, 그리고 내 HWLayer.m aswell에 Bomb.h을 가져옵니다

CCSprite 파일은 다음과 같다 내 코드에서 사용하는 경우와, 여기에 있습니다 :

Bomb *bombe = [[Bomb alloc] init]; 
bombe.position = explosionPoint; 
bombe.length = player.explosionLength; //player is another CCSprite class. This one is from the method. ....fromPlayer:(PlayerSprite *)player 
//Logging here works, tested and the bombe.position is valid and .length is valid 
[currentBombs addObject:bombe]; 
NSLog(@"%@",currentBombs); //Here doesn't, guessing crash is at^

로 말했다, 그것은 addObject: 라인에 충돌합니다. 나는 이유를 알 수 없다. 단지 클래스가 아닌 CCSprite를 Bomb 클래스로 대체했기 때문이다. 충돌은이 왼쪽에있는 것은 이들의 몇 천 출력 (lldb) 그냥 : 설명을 말한다, 그래서 오류가 내 CCSprite 서브 클래스의 가정 것이다

enter image description here

. 하지만 bombe. * 로깅은 정상적으로 작동했습니다!

왜 작동하지 않는 사람이 있습니까?

편집 :

enter image description here

+1

. 디버그 네비게이터의 맨 아래에 슬라이더를 맨 오른쪽으로 놓으면 * all * 프레임이 표시 될 수 있습니다. –

+0

@MartinR 예! 편집 된 질문을보십시오. 다른 것을 말합니까? –

+0

그것은 확실히 무한 재귀처럼 보입니다. 메소드를 게시 할 수 있습니까? - [CCSprite description] 및 (구현 한 경우)'- [Bomb description]'? – Mar0ux

답변

0

편집 :

NSLog(@"%@",currentBombs); //Here doesn't, guessing crash is at^

귀하 %의 @가 NSString을 의미한다. currentBombs는 int 일 가능성이 높습니다.

NSLog(@"%i",currentBombs); //Here doesn't, guessing crash is at^

CCSprite는 텍스처를 요구하십시오. 당신은 (아마도?) CCSprite을 가지고있을 수는 있지만, 그게 CCSprite을위한 것이 아닙니다.

당신은이 목적을 위해 CCNode를 사용하는 것이 좋습니다 :

CCNode* node = [CCNode new]; 

당신이 당신의 폭탄을 추가하고, 주위에 CCNode를 이동할 것 이동할 수있는 본격적인적인 Cocos2D 객체 등이다 이 같은 :

Bomb *myBomb = [Bomb new]; //or whatever 
CCNode* bombNode = [CCNode new]; 

//add the bomb to the node 
[bombNode addChild:myBomb]; 

//move the node 
bombNode.position = CGPointMake(10, 20) 

이 효과적으로 당신은 아무것도 표시하지 않고 당신이 원하는대로 추가 할 수있는 무언가를 가지고, 노드에서 myBomb을 제거 할 수 있습니다,하지만 당신이 원하는 때, 쉽게 수행 할 수 있습니다.

CCSprite의 설명 방법 "무한"재귀처럼 보이는 행운

+0

Currentbombs는 NSMurableArray입니다.) Edt : CCNode에 서브 클래 싱하여 충돌을 멈 춥니 다. 기능이 유지되는지 조사합니다. –

+0

-1'Your @ @는 NSString을 의미합니다. currentBombs는 int' 가능성이 높습니다 : 둘 다 잘못되었습니다. – Mar0ux

+0

@ Mar0ux 배열을 기록하는 더 좋은 방법이 있습니까? 나는 항상 % @ –

-1

이 방법을 시도 :

Bomb *bombe = [Bomb spriteWithFile:@"yourFile.png"]; 
bombe.position = explosionPoint; 
bombe.length = player.explosionLength; 
[currentBombs addObject:bombe]; 
NSLog(@"%@",currentBombs); 
+0

나는 실제로 이미지가 있기를 원하지 않는다 - 그러나 어쨌든 그것을 시도했지만 여전히 충돌한다. –