Search code examples
cocos2d-iphoneinitnslog

Instructions.m (instructions for the game) are not printing out the instructions?


I am creating an iphone application and for some reason, the instructions are not coming up when I run the code. This is my instructions class. When I run the program, nothing shows up.

Shouldn't "The object of this game is" show up on the screen?

Thank you for whatever help/knowledge you can provide me :)

#import "Instructions.h"
#import "MainMenu.h"

@implementation Instructions

+ (CCScene *) scene
{
    CCScene * scene = [CCScene node]; // scene is an autorelease object
    Instructions * layer =  [Instructions node]; // later is an autorelease object
    [scene addChild: layer]; // add layer as a child to scene
    return scene; // return the scene
}

- (id) init
{
    if ( ( self = [super init] ) )
    {
        [ self how ];
    }
    return self;
}

- (void) how
{
    NSLog(@"The object of this game is ");
}
@end

Solution

  • NSLog does nothing on the screen. It just prints your text in Xcode's console.

    To display text in the screen, try making a label. Like this:

    - (void) how
    {
        // Create the label
        CCLabelTTF *label = [CCLabelTTF labelWithString:@"The object of this game is..." fontName:@"Arial" fontSize:30];
    
        // Position it on the screen
        label.position = ccp(160,240);
    
        // Add it to the scene so it can be displayed
        [self addChild:label z:0];
    }
    

    For more about labels: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:labels