Hello guys,
I have two layer: GameplayLayer and HUDLayer. In game have a limited number of victims to throw to a vulcan and I need check how many victims the player has and I need to show in a HUD, but I having problem to import this variable right. Well, when I debug, the variable I'm using in GameplayLayer show that I have only one victim, but in HUDLayer show that I have 68 victims. I don't know what is happening and I try to Googled but still don't understand why is this happening.
I'm new in Object-C and Cocos2D and my english is not good.
Thanks
Gameplay.h
#import <Foundation/Foundation.h>
#import "CCLayer.h"
#import "cocos2d.h"
#import "Box2D.h"
#import "GLES-Render.h"
#import "MyContactListener.h"
#import "CCPanZoomController.h"
@interface GameplayLayer : CCLayer
{
int limiteVitima;
}
+(int)mensagemVitima;
Gameplay.mm
@implementation GameplayLayer
+(int)mensagemVitima
{
CCLOG(@"ENTRANDO NA MENSAGEM VITIMA");
return limiteVitima;
}
HUDLayer.h
#import <Foundation/Foundation.h>
#import "CCLayer.h"
#import "cocos2d.h"
#import "GameplayLayer.h"
@interface HudLayer : CCLayer
{
@public
int limiteVitima;
}
HUDLayer.mm
#import "HudLayer.h"
#import "GameplayLayer.h"
@implementation HudLayer
-(void)criaHud
{
CCLOG(@"CRIOU HUD");
CCLOG(@"limite vitima HUD antes de MensagemVitima -- %i", limiteVitima);
limiteVitima = [GameplayLayer mensagemVitima];
vitimaHud=[NSString stringWithFormat:@"%d", limiteVitima];
vitimaLabelNumero= [CCLabelTTF labelWithString:@"%@" fontName:@"Helvetica" fontSize:16];
[vitimaLabelNumero setString:[NSString stringWithFormat:@"%@",vitimaHud]];
[vitimaLabelNumero setPosition:ccp(80, 470)];
[self addChild:vitimaLabelNumero];
}
-(id)init
{
if((self = [super init]))
{
[self schedule:@selector(updateHUD:) interval:0];
[self criaHud];
}
return self;
}
-(void)atualizaHUD
{
limiteVitima = [GameplayLayer mensagemVitima];
vitimaHud=[NSString stringWithFormat:@"%d", limiteVitima];
[vitimaLabelNumero setString:[NSString stringWithFormat:@"%@",vitimaHud]];
}
-(void)updateHUD:(ccTime)dt
{
CCLOG(@"limiteVitima HUD -- %i", limiteVitima);
[self atualizaHUD];
}