First off, hello!
I'm a newcomer to the world of JUCE and C++ programming, so apologies in advance if my phrasing is a bit imprecise. I've begun a process of creating a series of progressivley more complex applications using the JUCE framework to learn its ins and outs and really learn C++ in a more hands-on way, and my latest project is a clone of the tile-based web game '2048' (http://gabrielecirulli.github.io/2048/). I realize that JUCE isn't necessarily designed with this kind of application in mind, but I'd really like to familiarize myself with the JUCE framework and its best practices while having a bit of fun along the way!
Right now, I have a MainContentComponent which contains an instance of a custom TileGrid class, which contains an OwnedContentArray of 'Tile' components and methods for the manipulation of these tiles during gameplay. My MainContentComponent contains a KeyListener for handling user input and a ComponentAnimator for animating my Tile components. I'm currently doing this by iterating through each component in my TileGrid's OwnedContentArray of Tile components, displaying them with the addAndMakeVisible method of my MainContentComponent, and animating them with my MainContentComponent's ComponentAnimator depending on behaviors specified in each Tile component class.
I've attached a little diagram of my layout to help illustrate how my application works:
My application works perfectly, but I'd like to make it a bit more elegant and compartmentalized by putting all of my animation functionality outside of my MainContentComponent.
My question is, what is the best way to add and manipulate child components of my MainContentComponent from outside of my MainContentComponent? Or, more generally, what is the best way to add child components to another component from outside of the (to-be) parent component?
Right now, I'm planning on writing an Animations class that contains all of my animation methods, and constructing it with a pointer to the Component that instantiated it (my MainContentComponent, in this case). Theoretically, it can then add child components to its instantiating component by dereferencing the pointer to the component that instantiated it and calling its addAndMakeVisible method.
Again, apologies if I'm not articulating this very well. These forums have been immensely useful thus far, and I've been able to understand a number of specific hangups I've encountered through perusing the forums. However, as a C++ noob it's been a little bit difficult to find answers to some of my questions involving some of the bigger-picture layout and best practice-type questions I've encountered.
Thanks in advance!