Search code examples
cocos2d-x

How to exchange data between two layer in cocos2d-x?


I have Layer A with the skill button and Layer B with the plyer sprite, what I need is that, when I touch the skill button and the plyer will use the skill. How can I let the Layer B know that when I touch the button? Is there anyone can show me with simple demo?


Solution

  • I think the best way is use a Singleton structure. In example, do a DataModule, create getters and setters, and call them using the static pointer to write or read data.