Auto Pause when entering background

Forums Programming cocos2d support (graphics engine) Auto Pause when entering background

This topic contains 6 replies, has 4 voices, and was last updated by  tonyngo 2 years, 8 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
Author Posts
Author Posts
August 26, 2011 at 9:55 pm #234724

alexasha
Participant
@alexasha

I know how to call method from AppDelegate.

//IN APP DELEGATE
[GameHUD pause];

//IN GAME HUD
+(void)pause{
NSLog(@"Pause");
}

But I can’t call any method in GameHUD for some reason.

/IN GAME HUD
+(void)pause{
NSLog(@"Pause");
[self displayPause]; //GET UNRECOGNIZED SELECTOR ERROR HERE
}

I don’t know why this doesn’t work. What am I doing wrong?

Thanks!

August 26, 2011 at 10:06 pm #344964

bazcocos
Participant
@bazcocos

calling a non-static (instance) function from within a static (class method) function. I think… ts late though.

August 26, 2011 at 10:26 pm #344965

alexasha
Participant
@alexasha

What would be the best way to solve my problems?

August 26, 2011 at 10:59 pm #344966

Blue Ether
Participant
@blue-ether

Many possibilities.

1. Make pause an instance method instead of a static method.

2. Make displayPause a static method instead of an instance method

3. Make your GameHUD class into a singleton

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html

(Search for “Creating a Singleton Instance”)

August 26, 2011 at 11:10 pm #344967

alexasha
Participant
@alexasha
+(void)pausedFromBackground{
[[[self alloc] init] openPause];
}

-(void)openPause{
NSLog(@"Open Pause Layer");

}

This is how it worked.

But now if I try to add child from openPause it doesn’t work.

August 27, 2011 at 12:34 am #344968

Blue Ether
Participant
@blue-ether

Yeah, that’s not “how it worked”. You’re creating an entirely new instance of your HUD every time you unpause, without bothering to clean up the old one, and you’re retaining it without storing a reference. That code makes me sad. You are apparently way over your head and need to go back and learn more about the basics of C/Objective C/programming first.

August 27, 2011 at 12:48 am #344969

tonyngo
@tonyngo

I agree with @blue-ether that you should learn more about the basics of Objective-C first, no offense intended. When you are ready, google for NSNotificationCenter examples. That class will solve your problem here.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.