• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [HOW TO?] Implement a Component System in GML

xDGameStudios

GameMaker Staff
GameMaker Dev.
I wanted to know what would be the correct and better approach to create a component system in GML.
Thank you in advance for your time and help.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
For example GUI System that has:

--- GUI_Component
--- --- GUI_Containers
--- --- --- GUI_Windows
--- --- --- GUI_Grids
--- --- GUI_Sprites
--- --- --- GUI_Frame
....

Containers can contain Components

The problem: each instance is updated, drawn.. during it's event... what if they depend on their father...

father update should update it's children (contained instances).
 

ZeDuval

Member
It's all about storing references to all child-objects/components inside the parent-objects/container, having a well thought out overall structure/system, and first and foremost: Writing a ton of scripts to make the whole thing atleast somewhat managable. Did something like this, thought it would be fun. It wasn't. ;)
Nevertheless, a few tips/suggestions:

Let every component draw itself as surface in the draw event and use a user_event for the code where the surface gets created/recreated(!). This is the "repaint" event, which would be called to create the initial surface, when the surface would be destroyed through something like minimizing the game window, and when the parentcontainer says so. Whenever one component would invalidate the draw state of itself it would tell its parentobject, which would then iterate through all childcomponents and call their repaint-event in order to revalidate the whole container/component group.

Let every component also store a reference to its parentcontainer. You can then put something like this into the step event or an alarm or whatever:
Code:
If !instance_exists(daddy) instance_destroy();
And at last: Always store relative xy coordinates, they will be more important than the actual xy vars of all components. But this won't actually be enough, you'd need to write something like a panel stack/grid/canvas system.

GUI-stuff sucks. :rolleyes:
 
Top