Hi.
What is your favourite design pattern for games in cocos2d-x c++ language?
I have some principles.
0. Use Node for base class.(Don’t use CCObject or your custom class for this!)
1- Don’t use singleton other than cocos singleton. (I mean Director)
2- Don’t use global variables. Add function parameters instead. (no problem with constants in global scope)
3- Don’t call public method of one class in another one, other than another one is parent of that class. (loose coupling)
4- Use custom events for communication between classes.
5- Use cocos action system for game logic. This system is very powerful.
My personal approach are:-
If it makes sense use singleton whenever you can.
Avoid unnecessary inheritance, not more then 2-3 level.
Never used Ref though, but willing to.
Never use Static variables specially bool, if this is the end of world still avoid it.
use struct{} whenever you manage data and if game is not resource heavy.
Find out earlier what is better AOS vs SOA pattern with struct{} implementation for game performance.