Data Model binding to functions/objects

Data Model binding to functions/objects
0.0 0


I am looking for easy ways to manage data and its UI update.

I know that component based / MVC aren’t used in cocos2d-iphone/-x.
But is there an existing way to do one-way binding / two-way binding between data and UI?

For example, in one-way binding, when I edit the value GameData::score, the GameLabel should be updated.

Or, are the observer pattern, or MVVM common in cocos2d?



Hi, you can use CCNotificationCenter to achieve that. It is supported in cocos2d-x-0.12.0. If you want to know how to use it, you can refer to ExtensionsTest—>NotificationCenterTest.


Thanks James, I will try this out. :slight_smile:


Data-driven is an important feature planned in cocos2d-iPhone/-x 2.0.
But I still have no idea about component-based architecture. In theory it will slow down the performance a lot. Im not sure where can I draw the line to keep the balance between flexibility and performance.