C
candlelight2007
Guest
There is nothing earth shattering in what I am about to say and to many seasoned GM2 devs here it is probably an obvious thing. But perhaps it will be useful to some newcomers like me who stumble into this later.
So after the first two weeks of digging through tutorials, manuals and forums, certain things slowly begin to make sense. One discovery that I made for myself that wasn't obvious to me at all is this. There are objects in my project that need instances of other objects to be drawn on top of them (think buttons inside a panel object). I would usually create them inside Draw (or Draw GUI) event. It all seemed to be working well and I was moving along with the project. Until at some point during debugging I added a show_debug_message to display the id of the instance of one of the objects that I created in Draw event. When I ran the game I suddenly discovered that Draw kept creating new instances continuously without me even realizing it! On the screen everything looked normal but the debug messages kept piling up with dozens of new instance ids. Not what i expected at all! When I checked, DrawGUI turned out to be doing the same thing.
I know I know. When I dug into the documentation, I found out that both Draw and DrawGUI apparently re-draw themselves every frame. What I ended up doing is adding instance_exists check wherever I had objects instantiated inside Draw event. Lesson learned. It may be by design but sure as heck it wasn't intuitive to me. So hopefully someone else might find this helpful. Cheers!
So after the first two weeks of digging through tutorials, manuals and forums, certain things slowly begin to make sense. One discovery that I made for myself that wasn't obvious to me at all is this. There are objects in my project that need instances of other objects to be drawn on top of them (think buttons inside a panel object). I would usually create them inside Draw (or Draw GUI) event. It all seemed to be working well and I was moving along with the project. Until at some point during debugging I added a show_debug_message to display the id of the instance of one of the objects that I created in Draw event. When I ran the game I suddenly discovered that Draw kept creating new instances continuously without me even realizing it! On the screen everything looked normal but the debug messages kept piling up with dozens of new instance ids. Not what i expected at all! When I checked, DrawGUI turned out to be doing the same thing.
I know I know. When I dug into the documentation, I found out that both Draw and DrawGUI apparently re-draw themselves every frame. What I ended up doing is adding instance_exists check wherever I had objects instantiated inside Draw event. Lesson learned. It may be by design but sure as heck it wasn't intuitive to me. So hopefully someone else might find this helpful. Cheers!