Hello,
In my game I use Layers. I have one for my player, and one for the controls. How can I communicate variables between them? I have 3 vars that need to be able to be changed in both layers. How can I do that?
A fast, easy to use, free, and community supported 2D game engine
Hello,
In my game I use Layers. I have one for my player, and one for the controls. How can I communicate variables between them? I have 3 vars that need to be able to be changed in both layers. How can I do that?
You will need to read about messaging and selectors. This link should be increadibly helpful and should be able to answer all your objective C related questions...
http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtHowMessagingWorks.html#//apple_ref/doc/uid/TP40008048-CH104-SW1
Hope this helps.
@Codemattic
Thank you!
Can someone help me with explaining the second post in this topic? http://www.cocos2d-iphone.org/forum/topic/1222
I have
GameTankLayer *GTLayer;
in my .h file, and then I have:
[GTLayer setTankRotation:5];`
in my .m file. It doesn't give errors, but the action isn't executed either. What am I missing?
you have to set GameTankLayer to point to a GTLayer that youve already created before you can send it messages. Right now GameTankLayer is nil, and it will ignore messages.
Okay, thank you. How can I do that? Sorry for all my questions, but I am a big n00b in objC.
btw, I just noticed the typo in the title. It of course should be 'communication between two layers'.
[typo fixed]
create your new GTLayer and save it in a variable, lets call it myGTLayer.
create your other object, lets call it myObject.
then: [myObject setGameTankLayer:myGTLayer];
You must log in to post.