This question is semi-similar to the one asked here
But the difference is that I’m using cocos2d.
I have a method named screenshot in my AppDelegate. It’s obviously used to take a screenshot. I want to call this method in another class, but simply doing [self screenshot]; isn’t working out because I get the warning ‘GameOver’ my not respond to ‘-screenshot’.
All I want is for the screenshot method to be called in GameOver.
Thanks!
You can’t call a method that does not exists – it will generate a runtime error.
If you want to call a method of AppDelegate from GameOver you should have a pointer to AppDelegate object if the method is not static:
If the method is static
I suppose you have only one object AppDelegate and you can make a static method
of class AppDelegate that will return your object singleton. And so you will be able to call
screenshotmethod from GameOver object or from any other place like this:Such thing is done in CCDirector, CCTextureCache, SimpleAudioEngine, … classes in Cocos2D