Best approach for a little 2d game?

Hey smart & beautiful people of juce!

I’m learning c++ and juce and I just love it!

I thought I should try to build a little 2d game but I’m not sure what the best practice/approach would be.

I would like my game to have a few “scenes”. A menu and highscores and a couple of in-game scenes. The smartest way I can think of is to create the scenes as child components to my MainContentComponent where I use switches with a "game-state" integer to update and repaint the relevant scene. Would this be a good way to approach things?

If so, what would be the most elegant way of jumping between the scenes? Going with game data from the in-game scene to highscores scene for example?

It makes a lot of sense to me to create methods in MainContentComponent that I then would call from the child components but I'm too newb to pull that syntax off, I understand how to recieve stuff in the constructor of the child component but how do I create a pointer to the MainContentComponent so that I can send it as an argument?

I obviosly need to learn more c++ and become a better programmer in general but I like hands-on learning and juce is so much fun, I thought I should just throw this out here and hope for some compassionate soul:)


Did you check out OpenGL and SDL. "The SDK's themselves" I did get some funny results with those before trying Juce for vst.

If you want to program your game from scratch (which I'm not sure I'd totally recommend if you're newish to programming or C++), depending on the needs of your game there are a ton of things to sort out in order to make the game function correctly at different framerates, on different system configurations, etc. I highly highly recommend this YouTube playlist as this is where I got started developing my own game engine (and this guy does a lot of other great stuff too, his OpenGL playlist is incredible). He uses Qt, but all the code/concepts are pretty easy to port over to JUCE if you know what you're looking for in the documentation.

As for your specific problem, depending on the complexity of the scenes and your overall game I think what you've come up with is a solid idea. Each child component (scene) could have its own timer loop (via an inherited Timer) for refresh rate, assuming you'd design as having your rendering and game logic running on the same tick system (not how "real" games work, but very simple to implement and "good enough" for very simple games).

Making high quality games from scratch is pretty challenging, depending on how much of a perfectionist you are about designing your code the "right" way. Luckily, JUCE should allow you to iterate your code extremely quickly and you can be pretty sure it will run on all platforms with minimal changes.

Good luck!