Jump to content

Photo

Great Game Maker Wall Optimization Script


  • Please log in to reply
6 replies to this topic

#1 Koh

Koh

    Tamer Koh

  • Members
  • Real Name:Dominic
  • Location:Monsbaiya, Virginia

Posted 28 September 2012 - 06:21 AM

After reading about how to optimize Game Maker games to make them run faster, I decided to try out one method mentioned before, to combine all of the Wall objects into one sprite using a surface, then deleting them all, and creating one big wall, it worked out TREMENDOUSLY. So I thought it would be useful for me to share my script with everyone. It's not hard to do of course, but it could save time, and I recommend using it with every game that's bound to have a lot of Wall objects. You call this script in the Room Creation Code.

CODE

var; wallsurface=0; w=0;  //Variables for the Surface on which all the wall sprites will be put on, and the New Wall object that will be made.
wallsurface=surface_create(room_width,room_height+1);  //Prepare a surface as big as the room, adding an extra pixel vertically so we can have transparency.

surface_set_target(wallsurface);  //Prepare to draw on the surface.
draw_clear(c_white);  //Clear the entire surface with the desired transparent color.
with objWall{  //With all of the walls in the room...
    if object_index==objWall{  //If it's not inheriting from anything (you may want to handle slopes with their own combined slope object, for example...
        draw_sprite(sprite_index,-1,x,y);  //Draw their sprite on the surface at their location.
        instance_destroy();  //Then delete theirself.
    }
}
if sprite_exists(global.wallopsprite){sprite_delete(global.wallopsprite);}  //If there was a combined wall surface sprite made before, get rid of it.  This is crucial you store this, as these will build up if you don't get rid of them, and can crash the game.
global.wallopsprite=sprite_create_from_surface(wallsurface,0,0,surface_get_width(wallsurface),surface_get_height(wallsurface),true,false,0,0);  //Make a new sprite from the surface made of all the Wall objects.
w=instance_create(0,0,objWall);  //Make a brand new Wall object at the top left of the room;
w.sprite_index=global.wallopsprite;  //Set its sprite to the sprite made from the surface.
w.mask_index=w.sprite_index;  //Set its mask to its sprite.
surface_free(wallsurface);  //Free up the memory from that surface.
surface_reset_target();  //Reset the drawing location.

It's not much, but it's effect on a game with a lot of Wall objects like my game is TREMENDOUS. I have no lag whatsoever now. You are all free to use this icon_smile.gif.

#2 kurt91

kurt91

    Follower of Destiny

  • Members
  • Real Name:Kurtis
  • Location:Eastern Washington University

Posted 28 September 2012 - 07:13 AM

By "wall object", do you mean like solid objects in a side-scrolling game? I'm working on a Mega Man game, so could I just do this on all my solid objects and end up with one object that makes up the entire level?

#3 Koh

Koh

    Tamer Koh

  • Members
  • Real Name:Dominic
  • Location:Monsbaiya, Virginia

Posted 28 September 2012 - 08:35 AM

QUOTE(kurt91 @ Sep 28 2012, 08:13 AM) View Post

By "wall object", do you mean like solid objects in a side-scrolling game? I'm working on a Mega Man game, so could I just do this on all my solid objects and end up with one object that makes up the entire level?

Pretty much the "colliders" for your tiles. The "dummy" wall objects that don't do anything other than sit there and be solid for collisions. And yes, it combines them all into one wall object for the whole level icon_smile.gif.

#4 DarkFlameWolf

DarkFlameWolf

    Murana Wolford

  • Members

Posted 02 October 2012 - 08:24 AM

Yes, working on a Megaman game myself and this sounds interesting to use. Thanks Koh!

#5 Giggidy

Giggidy

    We live for chaos so that we may die for ourselves.

  • Banned

Posted 02 October 2012 - 03:40 PM

Eh... this sort of thing only sounds useful if you're using a really, really inefficient collision detection model.

#6 sigtau

sigtau

    *sip*

  • Members
  • Real Name:Will
  • Location:Spending too much time on this damn thing

Posted 05 October 2012 - 10:45 AM

QUOTE(Giggidy @ Oct 2 2012, 04:40 PM) View Post

Eh... this sort of thing only sounds useful if you're using a really, really inefficient collision detection model.


From what I gather, Game Maker's pretty inefficient. I've never used it myself, but it sure does sound like it... icon_unsettled.gif

#7 Koh

Koh

    Tamer Koh

  • Members
  • Real Name:Dominic
  • Location:Monsbaiya, Virginia

Posted 05 October 2012 - 11:17 AM

QUOTE(sigtau @ Oct 5 2012, 11:45 AM) View Post

From what I gather, Game Maker's pretty inefficient. I've never used it myself, but it sure does sound like it... icon_unsettled.gif

It's not that GM is inefficient, but moreso that it's an interpreted language. So because of that, there's another layer to the code, which slows down processing time further. Hardly noticeable with simple games, but as you add more objects and have a lot of things operating at once, unless you learn to optimize, you'll reach a lagging point fairly quickly.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users