GameMaker ds_maps general practice question

S

SVG

Guest
Man I can't believe that I've never used ds_maps before lol.

So is it generally better to create a ds_map in the CREATION event and destroy it at the end of something like room change or game ending...

...or...

creating a ds_map in the STEP you need it, get the info like from a skeleton_bone_state_get() then destroy in asap?

Just learning good practices before I screw something up. Thanks!
 

FrostyCat

Redemption Seeker
You should create the map in the Create event and free it in the Cleanup event (see this post for details). Repeated allocate-deallocate cycling is bad for performance, and it's the main reason why that function lets you provide an existing map instead of returning its own.
 

rIKmAN

Member
If you are specifically talking about the skeleton_bone_state_* functions then you should be using the Animation Update event, not the Step Event.
According to the code example in the manual (http://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/sprites/skeletal animations/skeleton_bone_state_get.html) it's normal to be creating / destroying a locally scoped map each frame to read the bone data into.

Doing a ds_map_clear would also work if you wanted to use an instance variable to hold the map data instead, but I'm not sure if this is faster than destroying / recreating a map each frame.
 
S

SVG

Guest
You should create the map in the Create event and free it in the Cleanup event (see this post for details). Repeated allocate-deallocate cycling is bad for performance, and it's the main reason why that function lets you provide an existing map instead of returning its own.
Perfect, thanks FrostyCat! Also thanks for the post, nice to have 1 flippin spot to clean up at haha!



If you are specifically talking about the skeleton_bone_state_* functions then you should be using the Animation Update event, not the Step Event.
According to the code example in the manual (http://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/sprites/skeletal animations/skeleton_bone_state_get.html) it's normal to be creating / destroying a locally scoped map each frame to read the bone data into.

Doing a ds_map_clear would also work if you wanted to use an instance variable to hold the map data instead, but I'm not sure if this is faster than destroying / recreating a map each frame.
Yes rlKmAN I was referring to that specifically. The link you posted is exactly why I asked cause it doesn't say if you can create a custom map once in the create event then just refresh and update it in the Animation Update, then destroy is later. It didn't seem like I needed to keep re-creating the same map and destroy it in the same step every single step. That's what led me to post here. Or am I just overthinking it and it doesn't matter either way lol.
 
S

SVG

Guest
Speaking of spine :) Now that we have the Animation Event, I'm supposing that the built in ds_map that's created ("event_data") is ONLY created in the Animation Event and probably destroyed at the end of the same Event, making it not accessible earlier for the step events of course AND/OR making it late for the in the next step event. Still it's great to be able to use it, I'm just not able to find out if the event occurred exactly when I need to know.
 
Top