GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2010-07-31 23:24:08

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

Fragmenting a sprite using surface

So I'm doing and old school vector/line looking tank game. Everyting looks like it's line draw. It's prety cool.

For the tank explosion, I'm drawing the tank to a surface, centered on it, then I fragment the surface into bit using draw surface part. say 16 parts so the tank looks like it broke apart.


I have a problem and if memory serves I thing xot had a similar problem a while ago. The thing is, the resulting explosion seems to happen a few pixels ahead of the actual tank position. I looked and looked and can't seem to find exactly where the problem is... Is it the calculation to draw the tank on the surface? is it the draw part that is off by a few picels? I dont know. it seem to draw ahead, in the direction the tank is driving.

So here. I onlyt do thins is an act of dispear, Like you know me. I tend to fix my own problems but I need a fresh brain.

The GMK

explodetank script and explodeTankObj

link.png
pw: gmlscript

Last edited by icuurd12b42 (2010-08-01 00:04:22)

Offline

#2 2010-08-01 17:38:53

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

Re: Fragmenting a sprite using surface

Hmmmm. Host-A seems to be having database problems.

This probably isn't the answer you are looking for, but for lack of anything else to post, here is how I handled this sort of effect. This is sprite based but it should be readily adaptable to surfaces.

link.png
GM7 instance_explode() (mirror if above does not work)

EDIT
OK, Host-A is working again. I've downloaded it, but I won't be able to look into it for a few hours.

Last edited by xot (2010-08-03 13:14:07)


Abusing forum power since 1986.

Offline

#3 2010-08-01 23:10:47

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

Re: Fragmenting a sprite using surface

Fix appears simple.

In ExplodeTankObj replace:

Expand        xx[ct] = midx-size/2 + xat * bitsize;
        yy[ct] = midy-size/2 + yat * bitsize;

... with:

Expand        xx[ct] = tank.x - size/2 + xat * bitsize;
        yy[ct] = tank.y - size/2 + yat * bitsize;

The center of the bounding box is not necessarily the position of the object. You need to draw the pieces relative to the object, not the bounding box.

Q: Is there a reason you are creating a surface that has twice the necessary width and height? Seems extremely wasteful to draw all those pieces when ~75% of them have nothing drawn on them.


Abusing forum power since 1986.

Offline

#4 2010-08-02 02:41:51

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

Re: Fragmenting a sprite using surface

Thanks man. Works like charm!!

xot wrote:

Q: Is there a reason you are creating a surface that has twice the necessary width and height? Seems extremely wasteful to draw all those pieces when ~75% of them have nothing drawn on them.

Yeah, good catch. I was using sprite_width originaly, before i segragated the code from conceptual test to generic method. There I was using sprite_width instead of bounding box. I forget to remove that *2; originaly used to cheaply account for the rotation, a hack that I forgot to ajust in the final code.

A million thanks!

So, how do you like the feel of it?

[edit]
OK, over here, I lose the front edge of the tank. weird.

size = max(right-left,bottom-top);

size = max(right-left,bottom-top)+2; //still

size = max(right-left,bottom-top)+8; //fine

Last edited by icuurd12b42 (2010-08-02 02:54:05)

Offline

#5 2010-08-02 16:07:00

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

Re: Fragmenting a sprite using surface

Seems like a good system, it's pretty similar to mine. Surfaces are nice for supporting image_angle. I might extend mine with surfaces to support that. When I wrote it, I didn't think I'd be using image_angle, but I might.

Regarding the edge of the tank getting cut off, and I'm just guessing here, but maybe you should determine the dimensions of the surface with:

Expandsize = 2 * max( tank.x-left, right-tank.x, tank.y-top, bottom-tank.y );

Abusing forum power since 1986.

Offline

#6 2010-08-02 17:22:16

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

Re: Fragmenting a sprite using surface

Thanks, it's perfect now.

Offline

#7 2010-08-04 01:52:10

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

Re: Fragmenting a sprite using surface

Cool, glad it's working.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB