Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Wednesday, January 12, 2011

Labels quicksheet

A few thoughts on making labels in your game from Matt...
  • In HelloWorldScene.h create a new layer for score:
    • CCLayer* scoreLayer;
  • In HelloWorldScene.h import “CCLabelTTF.h” and add:
    • int numScore
    • CCLabelTTF* scoreLabel;
  • In HelloWorldScene.m
    • Initialize scoreLayer and add it to the scene
      • scoreLayer = [[CCLayer alloc] init];
      • [self addChild:scoreLayer z:2];
    • Initialize the amount of numScore (numScore = 0;)
    • Initialize what scoreLabel is going to hold
      • scoreLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Score: %d", numScore] fontName:@"Arial" fontSize:28];
(note: available fonts - http://daringfireball.net/misc/2007/07/iphone-osx-fonts)
      • scoreLabel.position = ccp(size.width - 100,size.height - 11);
      • scoreLabel.color = ccc3(255, 255, 255);
      • [scoreLayer addChild:scoreLabel];
    • In the update function:
      • When we check to see if a bullet has hit an enemy, in the part of code that says “YES HIT IT!” increase the score of numScore by however much (default of 100?)
      • Then update the scoreLabel to the new number
        • [scoreLabel setString:[NSString stringWithFormat:@"Score: %d",numScore]];
    • release the label in dealloc.

No comments:

Post a Comment