How do I manage to access data on one layer from another.
They are both on the same scene.
Sounds simple but I just can't manage to do it.
(Still trying to get my grasp on Objective-C and Cocos2D :D)
Sharing data between 2 layers on the same scene
(3 posts) (3 voices)-
Posted 1 year ago #
-
you could use the parent object to get a pointer to the scene
Posted 1 year ago # -
Usually the way this works is that it's easy to go from the top-down, but not from the bottup-up. Cocos2D has a hierarchy, just like Obj-C's object hierarchy. In this case, your game is made up of Scenes>Layers. For one layer to get info about another layer, it has to first talk through the parent (the scene) and then to the layer.
An easy way to do this is to have each layer be an instance variable in the scene's .h file. In each of the layer's .h files, set an instance variable that refers back to the scene. For any layer that wants to access properties or methods of another layer, all you have to do is first call up the scene and then the layer using dot syntax like:
In layer 1:
[parentScene.layer2 getMeALayer2Property];
Does that make sense?
Posted 1 year ago #
Reply
You must log in to post.