Reputation: 109
I'm writing the game in cocos2d (from Pablo Ruiz's book). Right now I have to create pause screen, and, according to the book, I have to create new function in AppDelegate.m (and in .h file) :
+(AppDelegate *) get {
return (AppDelegate *) [[UIApplication sharedApplication] delegate];
}
I'm getting errors : Expected a type; expected expression; Missing '[' at start of message send expression; Use of undeclared identifier 'AppDelegate'.
In another file, called GameScene.m, I created those functions:
-(void)resume
{
if(![AppDelegate get].paused)
{
return;
}
[AppDelegate get].paused = NO;
[self onEnter];
}
-(void)onExit
{
if(![AppDelegate get].paused)
{
[AppDelegate get].paused = YES;
[super onExit];
}
}
-(void)onEnter
{
if(![AppDelegate get].paused)
{
[super onEnter];
}
}
And I'm getting another set of errors : Use of undeclared identifier 'AppDelegate', four times.
Can someone explain me how to get rid of those errors?
Upvotes: 0
Views: 1245
Reputation: 22042
Cocos2d 2.0? Then Use AppController.
#import "AppDelegate.h"
AppController *app = (AppController*)[UIApplication sharedApplication].delegate;
Upvotes: 1
Reputation: 8507
Make sure you have added the following to your GameScene.h:
@class AppDelegate;
This will let the compiler know that the class AppDelegate
exists.
And in your GameScene.m:
#import "AppDelegate.h"
This lets you access AppDelegate members and methods.
Upvotes: 1