GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2009-05-31 16:08:06

brod
Member
From: NY, United States
Registered: 2008-12-14
Posts: 9
Website

How to make fast "Inverted" Destructible Terrain?

OK.. so usually when I try to create destructible terrain for my projects, I simply use surfaces and sprites, for example.

Expandvar surf;
surf = surface_create(room_width,room_height);
surface_set_target(surf);
  draw_clear(c_black,1);
  draw_sprite(sprite_index,0,0,0);
  draw_set_color(c_black);
  draw_circle(mouse_x,mouse_y,50,0);
surface_reset_target();
sprite_delete(sprite_index);
sprite_index = sprite_create_from_surface(...);
surface_free(surf);

And that's a usually fast method for me, since I use it once every time I click somewhere. However.. I've come up with a new concept for a game, which will have a unique method of destructible terrain.

Basically, instead of destroying terrain when you do something once, in this project, I want to destroy all the terrain farther than a certain radius, from a certain object. So basically..

lol.png
Everything outside of those green circles, would not be visible. I also need to have collision detection, so I have to also have it as a mask (unless there's some other way to achieve this) and thus, I've come here. Currently, what I'm doing is using the following code.

Expandvar surf1, surf2;
surf1 = surface_create(room_width,room_height);
surf2 = surface_create(room_width,room_height);

surface_set_target(surf1);
  draw_clear(c_black);
  draw_set_blend_mode(bm_subtract);
   draw_circle(mouse_x,mouse_y,50,0);
  draw_set_blend_mode(bm_normal);
surface_set_target(surf2);
  draw_clear(c_black);
  draw_sprite(sprite0,0,0,0);
  draw_surface(surf1,0,0);
surface_reset_target();

sprite_delete(sprite_index);
sprite_index = sprite_create_from_surface(surf2,0,0,room_width,room_height,1,1,0,0,0,0);
surface_free(surf1);
surface_free(surf2);

It works perfectly, but it utterly RAPES my fps. So.. I need another method of achieving this.

-------------------------------------------------------------------------

Also, I'm certain that the main reason causing the problem is the sprite_create_from_surface, so if anyone has any solutions that avoid using them, please comment. Thanks.

-------------------------------------------------------------------------
Uploaded a side GMK with my code. You can see the problem first hand.. click

Thanks for reading.

Last edited by brod (2009-05-31 16:08:41)

Offline

#2 2009-05-31 19:13:28

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: How to make fast "Inverted" Destructible Terrain?

Oh No! The topic is here now. I've been avoid this one. I never should have sent you your password. tongue

The problem is absolutely sprite_create_from_surface(surf2,0,0,room_width,room_height,1,1,0,0,0,0).

My only suggestion at the moment is to figure out how to divide your room into sections and capture smaller areas, and only areas that actually change. The size of the area makes a huge difference in the speed of sprite_create_from_*(). It's an interesting problem but I simply don't have the time right now to work on it.

Just for lulz, you might consider something completely asinine like saving the screen shot to disc and reloading it as a sprite. Sometimes asininity does amazing things in Game Maker. It's mindboggling stupid though, so don't feel bad if you don't want to embarrass yourself and your computer by trying it. laugh


Abusing forum power since 1986.

Offline

#3 2009-05-31 21:03:35

brod
Member
From: NY, United States
Registered: 2008-12-14
Posts: 9
Website

Re: How to make fast "Inverted" Destructible Terrain?

hehe.. it was only natural I would come for you, ;p

Yeah, I've been getting suggestions about making that, and have been tweaking with methods on how to do it. Guess I'll take the advice and just do it T-T

Offline

#4 2009-06-01 06:52:47

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: How to make fast "Inverted" Destructible Terrain?

The fastest method would probably to remove the sprite from the equation. Why not always draw the surface instead of the sprite. You can tile the room with 512x512 surfaces...

The only reason you would want to convert to a sprite would be because you need it's modified form for collision.

In this case, you forgot to draw a pixel at the bottom left to make sure prosision collision works (transparent pixel).

In any case, you better use an separate method for collision. There is a destructable terrain example that splits instance into smaller and smaller boxes. Visually it looks like crap but it's ideal for collision.

So if you use a surface for you visual destruction and the split box method for collision, you should get a pretty fast system

Offline

Board footer

Powered by FluxBB