• 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!

Basic surface (HELP)

6

66Gramms

Guest
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
 

Attachments

obscene

Member
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...

surface_set_target(track_surface);
// draw your tracks here
surface_reset_target();

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.
 
6

66Gramms

Guest
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 :/
 

zbox

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

Put
track_surface=-1
in your create event, and then where that surface_create line is, use

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

66Gramms

Guest
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 ^^
 
Top