Background
I have some old C++ games that I’d like to port to Android. They use a custom 2d game library and run on Windows, Mac and iOS… I don’t want to write the Android port from scratch because I’ve heard so many stories from developers about how fragmented and hellish it is to develop for Android. Soooo, I’ve stumbled upon Cocos2dx as a well tested, popular C++ game engine. My plan is to plug Cocos2d into my existing engine, thereby adding Android support to all my games. One small problem is that Cocos2d is a higher level SDK than what I need. I just need basic 2d graphic rendering, audio playing, input, etc. I don’t want or need a scene graph, animations, actions, etc, because my games already handles all that.
Current Problem
I’m currently struggling with the best way to draw the graphics. The Sprite class does most of what I need - rotate, scale, and colorize graphics… but it has to be added to a scene graph and it looks like it is designed to continue to exist over multiple frames. I want something more like Texture2d and Texture2d::drawAtPoint - load the graphic once, and then just draw it as many times as I want without managing the instances of it. That would replicate the functionality in my existing engine. However Texture2d doesn’t support rotation or color, which I need.
So right now I’m considering two ways to go.
- Using the Sprite class but removeAllChildren every frame, then recreate the sprites that I need every frame. This seems like it would have a huge amount of overhead. I did some quick tests, and it’s not completely horrible, also their might be ways to optimize it using some sort of reusable “sprite pools”.
- Using Sprite class but figuring out how to use it without the scene graph… I haven’t figured that out yet though and I’m not sure if it’s possible. I tried using a single Sprite without adding it to the scene graph. I set its position and rotation, then did Sprite:updateTransform(), then did Sprite::draw. However I could only draw the sprite one time per frame when doing this (I would want to use one Sprite to draw multiple times at different positions/scale/rotations.).
- Use Texture2d, but add all the features that I need to it. Rotated, scaled, colored, etc. I’m not sure how difficult this would be, or if it will require a lot of testing and bug fixes across different Android devices (the main thing that I’m trying to avoid by using Cocos2dx in the first place). Also, I saw another post about Texture2d::drawAtPoint being depracated… so this may be totally the wrong way to go.
Any thoughts on this? I just started using Cocos2dx - so I might be missing the obvious/standard way to do this. Cheers!