1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

Basic surface (HELP)

Discussion in 'Programming' started by 66Gramms, Jul 12, 2017.

  1. 66Gramms

    66Gramms Member

    Joined:
    Feb 2, 2017
    Posts:
    23
    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
     

    Attached Files:

  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,512
    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.
     
    66Gramms and DevGuyDonny like this.
  3. 66Gramms

    66Gramms Member

    Joined:
    Feb 2, 2017
    Posts:
    23
    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 :/
     
  4. zbox

    zbox Member GMC Elder

    Joined:
    Jun 21, 2016
    Posts:
    805
    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)
     
    66Gramms likes this.
  5. 66Gramms

    66Gramms Member

    Joined:
    Feb 2, 2017
    Posts:
    23
    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 ^^
     
    obscene likes this.

Share This Page