Coco2d - using CCBitmapFontAtlas - iphone

i'm trying to create a simple game with COCO2d but no luck so far...
when i'm trying to create a CCBitmapFontAtlas i get a error saying :
"_OBJC_CLASS_$_CCBitmapFontAtlas", referenced from:"
and also :
"'CCBitmapFontAtlas' is deprecated "
here is my header file:
#interface MainMenuScene : CCLayer
{
CCBitmapFontAtlas* startNewGameLabel;
}
(id) scene;
#end
and here is my implementation file :
#import "MainMenuScene.h"
#implementation MainMenuScene
(id) scene
{
CCScene scene = [CCScene node];
CCLayer layer = [MainMenuScene node];
[scene addChild:layer];
return scene;
}
-(id) init
{
if ((self = [super init]))
{
CCLOG(#"%#: %#", NSStringFromSelector(_cmd), self);
[self setVisible:YES];
startNewGameLabel = [CCBitmapFontAtlas
bitmapFontAtlasWithString:#"New Game"
fntFile:#"bitmapfont.fnt"];
//[CCLabelTTF labelWithString:#"New Game"
// fontName:#"AppleGothic"
// fontSize:48];
CGSize size = [[CCDirector sharedDirector] winSize];
startNewGameLabel.position = CGPointMake(size.width / 2, size.height / 2);
[self addChild:startNewGameLabel];
}
return self;
}
(void) dealloc
{
CCLOG(#"%#: %#", NSStringFromSelector(_cmd), self);
[super dealloc];
}
#end
I created both .FNT file and .PNG file with heir

You want CCLabelBMFont instead of CCBitmapFontAtlas.
startNewGameLabel = [CCLabelBMFont
labelWithString:#"New Game"
fntFile:#"bitmapfont.fnt"];

Use CCLabelBMFont instead. Will be removed 1.0.1

Related

Cocos 2D - Changing a Game Characters state from another class

I am learning Cocos2D from the Ray Wenderlich book in my spare time but also making changes to it if it does not explain how to do something that I could see myself needing in the future. I am currently stuck because of my very limited knowledge.
I wish to use the GamePlayLayer Class to randomly change the character state of the TBT class.
I have checked each State and they all work (checked by making them the spawn state) so the problem is most likely in the gamePlayLayer.m file where I have attempted to make my own method.
I seem to be able to get it to change its state to kStateThrowing but it changes straight back (in 0.3 of a second!) to kStateIdle before the animation plays and has the following output...
2013-11-21 13:45:07.938 Spaceviking[981:12c03] CHANGING STATE TBT!!!!!!
2013-11-21 13:45:07.939 Spaceviking[981:12c03] TBT->Changing State to throwing
2013-11-21 13:45:07.967 Spaceviking[981:12c03] TBT Going to Idle
2013-11-21 13:45:07.970 Spaceviking[981:12c03] TBT->changing state to idle
Any help with this would be greatly appreciated.
Code listed below...
// CommonProtocols.h
#ifndef SpaceViking_CommonProtocols_h
#define SpaceViking_CommonProtocols_h
typedef enum {
kDirectionLeft,
kDirectionRight
}
PhaserDirection;
typedef enum {
kStatespawning,
kStateIdle,
kStateWalking,
kStateIdleTilt,
kStatebackTilting,
kStateforwardTilting,
kStateAttacking,
kStateTakingDamage,
kStateThrowing,
kStateLosingALife,
kStateDead,
kStateTravelling,
kStateRotating,
kStatetest
}
CharacterStates; //1
typedef enum {
kObjectTypeNone,
kPowerUpTypeHealth,
kPowerTypeMallet,
kEnemyType1BT,
kEnemyType2BT,
kEnemyType3BT,
kEnemyTypePhaser,
kVikingType,
} GameObjectType;
#protocol GamePlayLayerDelegate
-(void)createObjectOfType:(GameObjectType)objectType
withHealth:(int)initialHealth
atLocation:(CGPoint)spawnLocation
withZValue:(int)ZValue;
-(void)createPhaserWithDirection: (PhaserDirection)phaserDirection
andPosition:(CGPoint)spawnPosition;
#endif
// GamePlayLayer.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "CCLayer.h"
#import "SneakyJoystick.h"
#import "SneakyButton.h"
#import "SneakyButtonSkinnedBase.h"
#import "SneakyJoystickSkinnedBase.h"
#import "Constants.h"
#import "CommonProtocols.h"
#import "TBT.h"
#interface GamePlayLayer : CCLayer <GamePlayLayerDelegate> {
CCSprite *vikingSprite;
SneakyJoystick *leftJoystick;
SneakyButton *jumpButton;
SneakyButton *attackButton;
CCSpriteBatchNode *sceneSpriteBatchNode;
}
#end
------------------------------------------------
// GamePlayLayer.m
#import "GamePlayLayer.h"
#implementation GamePlayLayer
-(void) dealloc {
[leftJoystick release];
[jumpButton release];
[attackButton release];
[super dealloc];
}
--DELETED BELOW 2 METHODS AS NOT NEEDED FOR THIS QUESTION--
-(void)initJoystickAndButtons {
}
-(void)applyJoystick:(SneakyJoystick *)aJoystick toNode: (CCNode *)tempNode forTimeDelta:(float)deltaTime
{
}
-(void) update:(ccTime)deltaTime {
CCArray *listOfGameObjects =
[sceneSpriteBatchNode children];
for (GameCharacter *tempChar in listOfGameObjects) {
[tempChar updateStateWithDeltaTime:deltaTime andListOfGameObjects:listOfGameObjects];
}
}
-(void) createObjectOfType: (GameObjectType)objectType
withHealth:(int)initialHealth atLocation:(CGPoint)spawnLocation withZValue:(int)ZValue {
if (objectType == kEnemyType1BT) {
CCLOG(#"creating 1BT");
TBT *tBT = [[TBT alloc] initWithSpriteFrameName:#"BT_anim_1.png"];
[tBT setCharacterHealth:initialHealth];
[tBT setPosition:spawnLocation];
[sceneSpriteBatchNode addChild:tBT
z:ZValue
tag:k1BTTagValue];
[tBT release];
}
}
--BELOW IS THE METHOD I HAVE CREATED TO CHANGE THE STATE--
-(void)changeState:(CharacterStates)newState {
[self stopAllActions];
int x = (arc4random() % 3);
TBT *tBT = [[TBT alloc]
initWithSpriteFrame:[[CCSpriteFrameCache
sharedSpriteFrameCache]
spriteFrameByName:#"BT_anim_1.png"]];
if (x>0) {
CCLOG(#"CHANGING STATE TBT!!!!!!");
[tBT changeState:kStateThrowing];
[tBT setDelegate:self];
[tBT release];
}
}
-(id)init {
self = [super init];
if (self !=nil) {
CGSize screenSize = [CCDirector sharedDirector]. winSize;
self.TouchEnabled = YES;
srandom(time(NULL));
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[[CCSpriteFrameCache sharedSpriteFrameCache]
addSpriteFramesWithFile:#"scene1atlas.plist"]; // 1
sceneSpriteBatchNode =
[CCSpriteBatchNode batchNodeWithFile:#"scene1atlas.png"]; // 2
} else {
[[CCSpriteFrameCache sharedSpriteFrameCache]
addSpriteFramesWithFile:#"scene1atlasiPhone.plist"]; // 1
sceneSpriteBatchNode =
[CCSpriteBatchNode batchNodeWithFile:#"scene1atlasiPhone.png"];
}
[self addChild:sceneSpriteBatchNode z:0];
[self initJoystickAndButtons];
BC *viking = [[BC alloc]
initWithSpriteFrame:[[CCSpriteFrameCache
sharedSpriteFrameCache]
spriteFrameByName:#"BCmoving_anim_1.png"]];
[viking setJumpButton:jumpButton];
[viking setAttackButton:attackButton];
[viking setPosition:ccp(screenSize.width * 0.19f,
screenSize.height * 0.19f)];
[viking setCharacterHealth:3];
[sceneSpriteBatchNode
addChild:viking
z:kVikingSpriteZValue
tag:kVikingSpriteTagValue];
[self createObjectOfType:kEnemyType1BT withHealth:3 atLocation:ccp(screenSize.width * 0.0439f, screenSize.height * 0.822f) withZValue:10];
---THE BELOW SELECTOR IS WHAT I HAVE USED TO DO A TIMED STATE CHANGE (METHOD ABOVE)--
[self schedule:#selector(changeState:) interval:1.0f];
[self scheduleUpdate];
}
return self;
}
#end
// TBT.h
#import <Foundation/Foundation.h>
#import "GameCharacter.h"
#interface TBT : GameCharacter {
//This is for the required animations
CCAnimation *tiltingAnim;
CCAnimation *transmittingAnim;
CCAnimation *loseLifeAnim;
CCAnimation *throwingAnim;
CCAnimation *afterThrowingAnim;
CCAnimation *shootPhaserAnim;
GameCharacter *vikingCharacter;
id <GamePlayLayerDelegate> delegate;
}
#property (nonatomic,assign) id <GamePlayLayerDelegate> delegate;
#property (nonatomic, retain) CCAnimation *tiltingAnim;
#property (nonatomic, retain) CCAnimation *transmittingAnim;
#property (nonatomic, retain) CCAnimation *loseLifeAnim;
#property (nonatomic, retain) CCAnimation *throwingAnim;
#property (nonatomic,retain) CCAnimation *afterThrowingAnim;
#property (nonatomic,retain) CCAnimation *shootPhaserAnim;
-(void)initAnimations;
-(void)changeState:(CharacterStates)newState;
#end
// TBT.m
#import "TBT.h"
#implementation TBT
#synthesize delegate;
#synthesize tiltingAnim;
#synthesize transmittingAnim;
#synthesize loseLifeAnim;
#synthesize throwingAnim;
#synthesize afterThrowingAnim;
#synthesize shootPhaserAnim;
-(void) dealloc {
delegate = nil;
[tiltingAnim release];
[transmittingAnim release];
[loseLifeAnim release];
[throwingAnim release];
[afterThrowingAnim release];
[shootPhaserAnim release];
[super dealloc];
}
--BELOW METHOD NOT NEEDED FOR THIS QUESTION
-(void)shootPhaser {}
-(CGRect)TBTboundingBox {
CGRect tbtBoundingBox = [self boundingBox];
float xOffset;
float xCropAmount = tbtBoundingBox.size.width * 0.5482f;
float yCropAmount = tbtBoundingBox.size.height * 0.1f;
tbtBoundingBox =
CGRectMake(tbtBoundingBox.origin.x + xOffset,
tbtBoundingBox.origin.y,
tbtBoundingBox.size.width - xCropAmount,
tbtBoundingBox.size.height - yCropAmount);
return tbtBoundingBox;
}
-(void)changeState:(CharacterStates)newState {
[self stopAllActions];
id action = nil;
[self setCharacterState:newState];
switch (newState) {
case kStatespawning:
CCLOG(#"TBT->Changing State to Spwaning");
[self setDisplayFrame:
[[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName:#"BT_anim_1.png"]];
break;
case kStateIdle:
CCLOG(#"TBT->schaning state to idle");
[self setDisplayFrame:
[[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName:#"BT_anim_1.png"]];
break;
case kStateThrowing:
CCLOG(#"TBT->Changing State to throwing");
action = [CCSequence actions:
[CCAnimate actionWithAnimation:throwingAnim
restoreOriginalFrame:NO],
[CCDelayTime actionWithDuration:1.0f],
//[CCAnimate actionWithAnimation:shootPhaserAnim
// restoreOriginalFrame:NO],
[CCCallFunc actionWithTarget:self
selector:#selector(shootPhaser)],
[CCAnimate actionWithAnimation:afterThrowingAnim
restoreOriginalFrame:NO],
[CCDelayTime actionWithDuration:0.1f],
nil];
break;
case kStateLosingALife:
CCLOG(#"TBT->Losing a life");
break;
case kStateDead:
CCLOG(#"TBT->changing state to dead");
action = [CCAnimate actionWithAnimation:loseLifeAnim];
break;
default:
CCLOG(#"unhandled state %d in TBT", newState);
break;
}
if (action !=nil) {
[self runAction:action];
}
}
-(void)updateStateWithDeltaTime: (ccTime)deltaTime andListOfGameObjects:(CCArray*)listOfGameObjects {
if (characterState == kStateDead)
return;
vikingCharacter =
(GameCharacter*)[[self parent]
getChildByTag:kVikingSpriteTagValue];
CGRect vikingBoudingBox =
[vikingCharacter adjustedBoundingBox];
CharacterStates vikingState = [vikingCharacter characterState];
if ((vikingState == kStateAttacking) && (CGRectIntersectsRect ([self adjustedBoundingBox], vikingBoudingBox))) {
if (characterState != kStateTakingDamage) {
[self changeState:kStateTakingDamage];
return;
}
}
if ((([self numberOfRunningActions] == 0) && (characterState != kStateDead)) ) {
CCLOG(#"TBT Going to Idle");
[self changeState:kStateIdle];
return;
}
}
-(void)initAnimations {
[self setTransmittingAnim:[self loadPlistForAnimationWithName:#"transmittingAnim" andClassName:NSStringFromClass([self class])]];
[self setThrowingAnim:[self loadPlistForAnimationWithName:#"throwingAnim" andClassName:NSStringFromClass([self class])]];
[self setAfterThrowingAnim:[self loadPlistForAnimationWithName:#"afterThrowingAnim" andClassName:NSStringFromClass([self class])]];
}
-(id) initWithSpriteFrameName:(NSString*)frameName{
if ((self=[super init])) {
if ((self = [super initWithSpriteFrameName:frameName])) {
CCLOG(#"### TBT initialized");
[self initAnimations];
characterHealth = 3.0f;
gameObjectType = kEnemyType1BT;
[self changeState:kStatespawning];
}
}
return self;
}
#end
My guess is you are not adding the TBT object as a child to anything (i.e. CCScene/CCNode/CCSprite). Try adding it to "sceneSpriteBatchNode" like in the createObjectOfType: method.
[sceneSpriteBatchNode addChild:tBT
z:ZValue
tag:k1BTTagValue];

COCOS 2D iPhone - Parsing variable between scenes and using in layer

I have the code of calling a new scene with the variable:
[[CCDirector sharedDirector] replaceScene:[GameScene sceneWithParam:item.tag]];
In GameScene.h
#interface GameScene : CCLayer {
}
+(id) sceneWithParam:(int)nvl;
#end
GameScene.m
+(id) sceneWithParam:(int)nvl
{
CCScene *scene = [CCScene node];
GameScene *layer = [GameScene node];
[scene addChild: layer];
return scene;
}
-(id) init
{
if( (self=[super init] )) {
}
return self;
}
I can't use the variable nil inside if( (self=[super init] )) {
I have already tried to set a property test, and to test = nvl; inside +(id) sceneWithParam:(int)nvl; but it is not possible.
Yes, it's not possible to use dynamic parameters in static methods. If you want to create your object with parameters, you have to create an init method, receiving parameters you need. E.g.:
-(id) initWithYourParam:(id)param
{
if ( (self=[self init]) ) {
self.propertyParam = param;
}
return self;
}

passing value from one scene to another

I've looked it up and most of the information is on making a singleton class. I just want to pass one value to my helloworldlayer.m from my menuscreen.m. What is the easy way to do this.
- (void) changeScenePlay
{
CCScene *testscene = [HelloWorldLayer scene];
testscene.number = 1;
[[CCDirector sharedDirector] replaceScene:testscene];
}
One of the methods i have tried is something like this, but this isnt working for me either.
how do i access a variable in a scene and change it.
Use variable member in HelloWorld layer class.
#interface HelloWorldLayer: CCLayer
{
int number;
}
#property(nonautomatic, assign) int number;
#end
#implementation HelloWorldLayer
#synthesize number;
+(CCScene *) sceneWithNumber:(int)inNumber
{
CCScene *scene = [CCScene node];
HelloWorldLayer *layer = [[[HelloWorldLayer alloc] initWithId:inNumber] autorelease];
[scene addChild: layer z:Z_SCENE tag:TAG_SCENE];
return scene;
}
-(id) initWithId:(int)inNumber
{
if( (self=[super init])) {
self.number= inNumber;
}
return self;
}
#end
Call sceneWithNumber instead of scene
- (void) changeScenePlay
{
CCScene *testscene = [HelloWorldLayer sceneWithNumber:1];
[[CCDirector sharedDirector] replaceScene:testscene];
}
create extern variable for this and do as you are doing.

Cocos2d Game crashing when replacing scene (Code Included)

so something is going haywire with my Cocos2d Game. I recently added in some code that would allow me to have a dialog message at the beginning of certain levels in my game. And whenever I go to restart a level (Which replaces the scene) of a level that has the dialog cclayer added to the current scene, I get a BAD ACCESS error through the iPhone simulator, and then if I run it on my iPhone 4S I'm getting a SIGARBT error that says
"* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'child already added. It can't be added again'"
This is my first cocos2d game I'm making. I've toyed a lot with cocos2d and have what I believe is a basic understanding. I have a lot of programming experience with other languages, but I only started learning objective-c about 3 months ago.
Here is my code.
GameDialog.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "GameData.h"
#interface GameDialogLayer : CCLayer {
NSString *dialogText;
}
#property (nonatomic, retain) NSString *dialogText;
+(CCScene *) scene;
-(void) addDialogWithText: (NSString *)text;
#end
GameDialog.m
#import "GameDialogLayer.h"
#implementation GameDialogLayer
#synthesize dialogText;
+(CCScene *) scene
{
CCScene *scene = [CCScene node];
GameDialogLayer *layer = [GameDialogLayer node];
[scene addChild: layer];
return scene;
}
-(id) init
{
if( (self=[super init]) ) {
// init the bg overlay
CCLayerColor *backgroundLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 175)];
[self addChild:backgroundLayer z:0];
// init the dialog box
CCSprite *dialogBox = [CCSprite spriteWithFile:#"dialog.png"];
dialogBox.position = ccp([[CCDirector sharedDirector] winSize].width / 2, [[CCDirector sharedDirector] winSize].height / 2);
[self addChild:dialogBox];
// init the dialog menu
CCMenuItemImage *dialogOkay = [CCMenuItemImage itemWithNormalImage:#"dialogOkayButton.png" selectedImage:#"dialogOkayButtonPressed.png" target:self selector:#selector(okayButton)];
CCMenu *dialogMenu = [CCMenu menuWithItems:dialogOkay, nil];
dialogMenu.position = ccp(dialogMenu.position.x, dialogMenu.position.y - 118);
[self addChild:dialogMenu];
}
return self;
}
-(void) okayButton
{
[GameData sharedGameData].isPaused = 0;
[[self parent] schedule:#selector(startCountdown:) interval:1];
[[self parent] removeChild:self cleanup:YES];
}
-(void) addDialogWithText: (NSString *)text
{
CCLabelTTF *dialogTextLabel = [CCLabelTTF labelWithString:text dimensions:CGSizeMake(180, 250) hAlignment:kCCTextAlignmentLeft fontName:#"MarkerFelt-Thin" fontSize:20];
dialogTextLabel.color = ccBLACK;
dialogTextLabel.position = ccp([[CCDirector sharedDirector] winSize].width / 2, [[CCDirector sharedDirector] winSize].height / 2);
[self addChild:dialogTextLabel];
}
- (void) dealloc
{
[super dealloc];
}
#end
And then the dialog is being added to my dialog property in my levelData class that is istantiated for each level and holds the properties of the level.
Here is the property holding it
#property (nonatomic, retain) GameDialogLayer *dialog;
And here is how I'm adding the dialog to the levelData dialog property
-(void) addDialog: (NSString *)dialogText
{
dialog = [GameDialogLayer node];
[dialog addDialogWithText:dialogText];
}
You are adding a node to the scene twice somehow, I had a look at your code and couldn't spot it but they are easy to find. Just add a breakpoint for all Objective C exceptions. The debugger will stop on the line causing the problem.
See here for how to add the breakpoint. You can change "Exception: All" to "Exception: Objective C" to avoid exceptions from CocosDenhesion if you are using it.

Pass level time to Congratulations scene cocos2d

Just wondered if someone could quickly give me a hand. Im building a simple puzzle slider game, ive added a timer to the game now and all i want to do is pass the time it took to complete the puzzle over to the congrats scene. Could anyone just have a look at my code see where im going wrong please?
play.h
#import "cocos2d.h"
#import "Box.h"
#interface PlayLayer : CCLayer
{
int timeInt;
int secs;
int mins;
CCLabel *timeLabel;
NSString *TotalTimeString;
}
#property (nonatomic, assign) int timeInt;
#property (nonatomic, assign) int secs;
#property (nonatomic, assign) int mins;
#property (nonatomic, retain) NSString *TotalTimeString;
#end
Play.m
#import "PlayLayer.h"
#import "Congrats.h"
#implementation PlayLayer
#synthesize timeInt;
#synthesize secs;
#synthesize mins;
#synthesize TotalTimeString;
-(id) init{
self = [super init];
TotalTimeString = [NSString stringWithFormat:#"Time: %02d:%02d", mins, secs];
timeLabel = [[CCLabel labelWithString:TotalTimeString dimensions: CGSizeMake(130,27) alignment: UITextAlignmentCenter fontName:#"Marker Felt" fontSize:25.0] retain];
timeLabel.position = ccp(155,430);
[self addChild:timeLabel];
[self schedule: #selector(tick2:) interval:1.0];
return self;
}
-(void) tick2: (id) sender{
timeInt++;
secs = timeInt % 60;
mins = timeInt / 60;
[timeLabel setString: TotalTimeString];
}
-(void) check: (id) sender data: (id) data{
int valueToCheck = 0;
bool breakOut = false;
for (int y=0; y < box.size.height && !breakOut; y++) {
for (int x=0; x < box.size.width && !breakOut; x++) {
Tile *tile = [box objectAtX:x Y:y];
if (tile.check != [box hashOfXY:x y:y]) breakOut = true;
valueToCheck++;
}
}
int totalTiles = box.size.width * box.size.height;
if (valueToCheck == totalTiles){
[[CCDirector sharedDirector] replaceScene:[CCFadeTransition transitionWithDuration:1 scene:[Congrats node]]];
CCScene *scene = [Congrats scene];
scene.TotalTimeTakenWhenDiedString = TotalTimeString;
[[CCDirector sharedDirector] replaceScene:scene];
}
}
#end
Congrats.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "PlayLayer.h"
#interface Congrats : CCLayer {
CCLabel *timeLabel;
NSString *TotalTimeTakenWhenDiedString;
}
#property (nonatomic, assign) NSString *TotalTimeTakenWhenDiedString;
+(id) scene;
#end
Congrats.m
#import "Congrats.h"
#import "DifficultyLevel.h"
#import "PlayLayer.h"
#import "PlayLayerMedium.h"
#import "PlayLayerHard.h"
#import "MainMenu.h"
#implementation Congrats
#synthesize TotalTimeTakenWhenDiedString;
+(id) scene {
// ‘scene’ is an autorelease object.
CCScene *scene = [CCScene node];
// ‘layer’ is an autorelease object.
Congrats *layer = [Congrats node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on “init” you need to initialize your instance
-(id) init {
// always call “super” init
// Apple recommends to re-assign “self” with the “super” return value
if( (self=[super init] )) {
timeLabel = [[CCLabel labelWithString: TotalTimeTakenWhenDiedString dimensions: CGSizeMake(130,27) alignment: UITextAlignmentCenter fontName:#"Marker Felt" fontSize:25.0] retain];
timeLabel.position = ccp(155,430);
}
return self;
}
-(void) goToGameplay: (id) sender {
[[CCDirector sharedDirector] replaceScene:[CCFadeTransition transitionWithDuration:1 scene:[MainMenu node]]];
}
}
#end
I was kind of hoping that, that would work. But i keep getting this error "error: request for member 'TotalTimeTakenWhenDiedString' in something not a structure or union"
Anyone help at all?
Cheers
Your problem is here:
CCScene *scene = [Congrats scene];
scene.TotalTimeTakenWhenDiedString = TotalTimeString;
The object scene is of type CCScene and you are trying to access TotalTimeTakenWhenDiedString on it. But that is a property of Congrats, not of CCScene.
Here's a suggestion which might work, by getting the Congrats object out from scene. (Caveat: I'm not familiar with cocos2d, and I only looked it up quickly here. This may be a terrible way to be doing it!)
Change here:
// add layer as a child to scene
[scene addChild:layer z:0 tag:1]; // tag it with 1
and here:
CCScene *scene = [Congrats scene];
Congrats *congrats = (Congrats *)[scene getChildByTag:1]; // get the congrats child object, which we tagged 1
congrats.TotalTimeTakenWhenDiedString = TotalTimeString;
[[CCDirector sharedDirector] replaceScene:scene];
... Why dont you just create a singleton class which you can use as a global object? and access/update it anywhere in the game?