Singleton method not getting called in Cocos2d

Posted by jini on Stack Overflow See other posts from Stack Overflow or by jini
Published on 2011-11-19T17:33:12Z Indexed on 2011/11/19 17:51 UTC
Read the original article Hit count: 226

Filed under:
|
|

I am calling a Singleton method that does not get called when I try doing this. I get no errors or anything, just that I am unable to see the CCLOG message.

Under what reasons would a compiler not give you error and not allow you to call a method?

[[GameManager sharedGameManager] openSiteWithLinkType:kLinkTypeDeveloperSite];

The method is defined as follows:

-(void)openSiteWithLinkType:(LinkTypes)linkTypeToOpen
{

    CCLOG(@"WE ARE IN openSiteWithLinkType"); //I NEVER SEE THIS MESSAGE

    NSURL *urlToOpen = nil;

    if (linkTypeToOpen == kLinkTypeDeveloperSite) 
    {
        urlToOpen = [NSURL URLWithString:@"http://somesite.com"];    
    }

    if (![[UIApplication sharedApplication]openURL:urlToOpen])
    {
         CCLOG(@"%@%@",@"Failed to open url:",[urlToOpen description]);
        [self runSceneWithID:kMainMenuScene];
    }

}

HERE IS THE CODE TO MY SINGLETON:

#import "GameManager.h"
#import "MainMenuScene.h"


@implementation GameManager
static  GameManager* _sharedGameManager = nil;
@synthesize isMusicON;
@synthesize isSoundEffectsON;
@synthesize hasPlayerDied;

+(GameManager*) sharedGameManager
{
@synchronized([GameManager class])
    {

        if (!_sharedGameManager) 
        {
            [[self alloc] init];
            return _sharedGameManager;
        }
        return nil;
    }

}


+(id)alloc
{

    @synchronized ([GameManager class])
    {
        NSAssert(_sharedGameManager == nil,@"Attempted to allocate a second instance of the Game Manager singleton");
        _sharedGameManager = [super alloc];
        return _sharedGameManager;
    }
    return nil;
}

-(id)init
{
    self = [super init];
    if (self != nil)
    {
        //Game Manager initialized
        CCLOG(@"Game Manager Singleton, init");
        isMusicON = YES;
        isSoundEffectsON = YES;
        hasPlayerDied = NO;
        currentScene = kNoSceneUninitialized;
    }

    return self;

}


-(void) runSceneWithID:(SceneTypes)sceneID
{
    SceneTypes oldScene = currentScene;
    currentScene = sceneID;
    id sceneToRun = nil;


    switch (sceneID) 
    {
        case kMainMenuScene:
            sceneToRun = [MainMenuScene node];
            break;

        default:
            CCLOG(@"Unknown Scene ID, cannot switch scenes");
            return;
            break;
    }

    if (sceneToRun == nil)
    {

        //Revert back, since no new scene was found
        currentScene = oldScene;
        return;
    }




    //Menu Scenes have a value of < 100
    if (sceneID < 100) 
    {
        if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
        {
            CGSize screenSize = [CCDirector sharedDirector].winSizeInPixels;
            if (screenSize.width == 960.0f)
            {
                //iPhone 4 retina
                [sceneToRun setScaleX:0.9375f];
                [sceneToRun setScaleY:0.8333f];
                CCLOG(@"GM: Scaling for iPhone 4 (retina)");
            }
            else
            {
                [sceneToRun setScaleX:0.4688f];
                [sceneToRun setScaleY:0.4166f];
                CCLOG(@"GM: Scaling for iPhone 3G or older (non-retina)");
            }

        }    

    }


    if ([[CCDirector sharedDirector] runningScene] == nil)
    {
        [[CCDirector sharedDirector] runWithScene:sceneToRun];
    }
    else

    {
        [[CCDirector sharedDirector] replaceScene:sceneToRun];

    }

}


-(void)openSiteWithLinkType:(LinkTypes)linkTypeToOpen
{

    CCLOG(@"WE ARE IN openSiteWithLinkType");

    NSURL *urlToOpen = nil;

    if (linkTypeToOpen == kLinkTypeDeveloperSite) 
    {
        urlToOpen = [NSURL URLWithString:@"http://somesite.com"];    
    }

    if (![[UIApplication sharedApplication]openURL:urlToOpen])
    {
         CCLOG(@"%@%@",@"Failed to open url:",[urlToOpen description]);
        [self runSceneWithID:kMainMenuScene];
    }

}


-(void) test
{


    CCLOG(@"this is test");

}
@end

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios