Frage

In my game I have platforms similar to Doodle Jump. They each have their own animation but they all in the end have the same tag for a b2ContactListener. Right now I am using a CCSprite but I do not think that will work. What should I do instead?

Currently I am using CCSprite and I get this crash (SIGABRT):

2011-11-19 15:56:57.555 App[11306:707] *** Assertion failure in -[CCLayerClass addChild:z:tag:], /Users/myName/Desktop/Projects/MyProjectName/MyProject/cocos2d/CCNode.m:390
2011-11-19 15:56:57.557 App[11306:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Argument must be non-nil'

I think this is because my CCSprite is nil correct? But I am not sure why it is nil. I declare it in my .h And then in my spawn method I do it like this (pseudo-code):

if (object type is NSString) {
[CCSprite spriteWithfile:];
}
else {
[CCSprite spriteWithCGImage:];
}
[self addChild mySprite];

Also if I use breakpoint in the if statements, it says Out of Scope. Any ideas on how I can this to properly work?

Thanks!

Answer: I ended up fixing this because the way I accessed my UIImage was incorrect. I ended up fixing it now by casting the object type and then it worked. Also as far as the efficiency goes, I was calling my one method like a game loop which I didn't want so i am fixing that now.

War es hilfreich?

Lösung

Perhaps you simply forgot to assign the created sprites to mySprite?

if (object type is NSString) {
mySprite = [CCSprite spriteWithfile:];
}
else {
mySprite = [CCSprite spriteWithCGImage:];
}
[self addChild mySprite];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top