Basic surface (HELP)


Hello Everyone!
So, i'm making a 2 player tank game and it's pretty much complete. There are only minor improvements left to be done and this is one of them. I would like to add tracks as my tank going on the map. I know the most efficient way to do it is by surfaces but i never worked with them before. Please could you help me with it, about how could i do that? I attach a picture about what i want to make



It's easier than you think...

First you create a surface. Do this in a create event of a controller object. Its as easy as ...

track_surface=surface_create(375,513); // or whatever size your screen is.

When you want to add tracks to it, do it in the draw event...

// draw your tracks here

And then you need to actually draw the surface using one of the draw_surface( etc ) commands. Probably again in a controller object before your tanks are drawn.

Give it a go and as you run into issues (you probably will :p ) we'll help you fix it.

Edit: Also you need to destroy the surface at the end of your game / room / whenever you are done with it.


Oh okay, i gave it a try yesterday based on a video but somehow it didn't success so i must have done something wrong (it was drawing the tracks for only 1-1 frame and after a few seconds i got a message "Out of memory") As soon as i get home i give it another try, based on this. Thank you and sorry for the noob question :/


GMC Elder
This is because you're creating a new surface every step and it runs out of memory.

in your create event, and then where that surface_create line is, use

if (!surface_exists(track_surface))
track_surface = surface_create(w, h)


It's very basic yet, but it's working and from now on i can do it ^^ I will surely spend more time using surfaces from now as I know the basics... Thanks for help people ^^