Hello everyone, I have a problem here that I could not solve.
When my CCMenuItem loads, it crashes due to SIGBART.
Here is the header:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Main.h"
#import "Player.h"
@interface UserInterface : CCLayer {
CCLabelTTF* scoreText;
CCLabelTTF* powerText;
CCMenu* mainMenu;
}
- (void) setPowerText:(NSString *)pt;
@end
and the main script:(you can ignore all the other parts... I only copy-and-pasted.... :P)
#import "UserInterface.h"
@implementation UserInterface
- (id) init {
if ((self = [super init])) {
// Score
scoreText = [CCLabelTTF labelWithString:@"Score: 0" dimensions:CGSizeMake(width / 2, 36) alignment:UITextAlignmentRight fontName:@"Marker Felt" fontSize:36];
scoreText.anchorPoint = ccp(1, 1);
scoreText.position = ccp(width - 5, height - 20);
[self addChild:scoreText z:1];
// Power
powerText = [CCLabelTTF labelWithString:@"Error: Power-up/down fatal error!" dimensions:CGSizeMake(width, 28) alignment:UITextAlignmentCenter fontName:@"Marker Felt" fontSize:28];
powerText.position = ccp(width / 2, 20);
powerText.opacity = 0.0f;
[self addChild:powerText z:2];
// Main Menu
// [CCMenuItemFont setFontName:@"Marker Felt"];
// [CCMenuItemFont setFontSize:18];
CCMenuItemFont* mainMenuItem = [CCMenuItemFont itemFromString:@"Main Menu" target:self selector:@selector(mainMenuGoback:)];
/* mainMenu = [CCMenu menuWithItems:mainMenuItem, nil];
mainMenu.position = ccp(980, 10);
[self addChild:mainMenu z:3];*/
}
return self;
}
- (void) draw {
glLineWidth(15);
for (int i = 0; i < health; i++) {
glColor4ub(255 - i * 10, i * 10, 0, 255);
ccDrawLine(ccp(30 + 18 * i, height - 20), ccp(20 + 18 * i, height - 50));
}
for (int i = 0; i < forcefield; i++) {
glColor4ub(0, i * 10, 255 - i * 10, 255);
ccDrawLine(ccp(30 + 18 * i, height - 70), ccp(20 + 18 * i, height - 100));
}
[scoreText setString:[NSString stringWithFormat:@"Score: %i", score]];
if (powerText.opacity > 0.0f) {
powerText.opacity -= 0.02f;
}
}
- (void) mainMenuGoBack:(id)sender {
NSLog(@"HOORAY! XP ( Look from the right.... )");
}
- (void) setPowerText:(NSString *)pt {
powerText.opacity = 255.0f;
[powerText setString:pt];
}
- (void) dealloc {
// End
[super dealloc];
}
@end
I have compared it to my other piece of code, which works fine:
Header:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Main.h"
#define NO_OF_STARS 50
@interface GameOverScene : CCLayer {
bool changingScene;
Star stars[NO_OF_STARS];
}
+ (id) scene;
@end
Main:
#import "GameOverScene.h"
#import "Level1.h"
#import "MenuScene.h"
@implementation GameOverScene
+ (id) scene {
CCScene* scene = [CCScene node];
[scene addChild:[GameOverScene node]];
return scene;
}
- (id) init {
if ((self = [super init])) {
changingScene = NO;
CCSprite* background = [CCSprite spriteWithFile:@"space.png"];
background.position = ccp(512, 384);
[self addChild:background z:-1];
CCLabelTTF* gameOverlabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Score for this level: %i", score] fontName:@"Marker Felt" fontSize:48];
gameOverlabel.position = ccp(512, 468);
[self addChild:gameOverlabel z:10];
[CCMenuItemFont setFontSize:36];
CCMenuItem* menuRetry = [CCMenuItemFont itemFromString:@"Retry this level" target:self selector:@selector(retry:)];
CCMenu* menu = [CCMenu menuWithItems: menuRetry, nil];
menu.position = ccp(512, 300);
[self addChild:menu z:9];
for (int i = 0; i < NO_OF_STARS; i++) {
stars[i].position = ccp(random() % width, random() % height);
stars[i].boostTime = 0;
stars[i].speed = (random() % 3) + 1;
}
}
return self;
}
- (void) draw {
for (int i = 0; i < NO_OF_STARS; i++) {
// Draw Stars
if (stars[i].boostTime > 0) {
stars[i].boostTime--;
}
glColor4f(255, 255, 255, 255); // Set color of star white
glPointSize(stars[i].speed); // size for star
ccDrawPoint(stars[i].position); // Draw
// Move star
stars[i].position.x -= stars[i].speed;
if (stars[i].position.x < -10) {
stars[i].position = CGPointMake(width + random() % 50, random() % height);
}
if (stars[i].boostTime > 0) {
stars[i].position.x -= stars[i].speed * (stars[i].boostTime / 3);
}
}
}
- (void) retry:(id)sender {
if (!changingScene) {
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.8 scene:[Level1 scene] withColor:ccWHITE]];
changingScene = YES;
}
}
@end
Could someone tell me where I am doing wrong? Thanks! I'm using 0.99.5.