2012-05-31 3 views
0

J'ajoute une couche à ma scène et je veux vérifier quand elle est complètement chargée en définissant un booléen après mon initialisation appelé doneInitializing à YES. Mais j'ai besoin d'y accéder en quelque sorte ... Comment je fais ça?Comment accéder à la propriété de CCLayer?

LoadingScreen.h

@interface LoadingScreen : CCLayerColor{ 
    CCLayer *hWL; 
} 

LoadingScreen.m

hWL = [HelloWorldLayer node]; 

[self addChild:hWL]; 

if(hWL.doneInitializing == YES){ // that is where I get stuck 
//do something 

} 

Je ne peux pas accéder à la doneInitializing variables ... POURQUOI?

HelloWorldLayer.h

@interface HelloWorldLayer : CCLayer 
{ 
    BOOL doneInitializing; 
} 



@property (nonatomic,readwrite) BOOL doneInitializing; 

HelloWorldLayer.m

@synthesize doneInitializing; 

Y at-il une meilleure approche pour atteindre cet objectif ??

Répondre

2

changer seulement cette partie:

@interface LoadingScreen : CCLayerColor{ 
    CCLayer *hWL; 
} 

à ceci:

@interface LoadingScreen : CCLayerColor{ 
    HelloWorldLayer *hWL; 
} 

OU utiliser cette ligne à la place:

if(((HelloWorldLayer *)hWL).doneInitializing == YES){ 

compilateur et le moteur d'exécution a besoin de savoir que vous obtenez un propriété du HelloWorldLayer au lieu du CCLayer. Bien que vous assignez hWL = [HelloWorldLayer node], hWL a été déclarée une plaine CCLayer et la ligne avec hWL.doneInitializing obtient des ennuis parce que pour l'exécution sait, un CCLayer n'a pas une propriété nommée doneInitializing. Vous devez dire à l'exécution "mec, hWL est une HelloWorldLayer" en déclarant hWL comme HelloWorldLayer ou en le castant à cette classe.

+0

Parfait. Merci :-) Je n'aurais pas pu y penser, mais c'est clair et évident, merci. –

Questions connexes