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

Problem with surface and lag

W

Will i am

Guest
this is just a test in which im trying to make shapes floating towards main object(thing). When they hit it, it should draw a new sprite of that main object with that peace or a shape that collided with it, but after a few collisions it starts to lagg for some reason and i cant figure out why.
Can anyone help me ?
Sorry for bad english :p
Here is the collision event:
Code:
var surf, w, ow, h, oh, xx, yy, r, angdif;
// we need to know what are sprites dimensions in order to make surface thats not too big
w = sprite_get_width(spr)
h = sprite_get_height(spr)

oh = other.sprite_height
ow = other.sprite_width
// these are the cordinates of the origin of a new image but also for drawing new image in middle of the surface
xx = sprite_get_xoffset(spr)+ow
yy = sprite_get_yoffset(spr)+oh

r = point_distance(x, y,other.x, other.y)

angdif = point_direction(x, y, other.x, other.y)-ang

surf = surface_create(w+2*ow, h+oh*2) // create surface

surface_set_target(surf)
draw_sprite(spr, 0, xx, yy) // draw first current sprite with 0 angle so that it doesnt lose any quality
draw_sprite_ext(other.sprite_index, 0, xx+cos(angdif*pi/180)*r, yy-sin(angdif*pi/180)*r, 1, 1, other.image_angle-ang, c_white, 1) // draw anothere peace(the one that is beight hit by)
surface_reset_target() // restart
spr = sprite_create_from_surface(surf, 0, 0, w+2*ow, h+2*oh, 0, 0, xx, yy) // chance sprite
surface_free(surf); // free surface from memory

with(other) instance_destroy() // destroy other object
and here the example(GM8, .gmk) if you want to take a closer look: http://www.mediafire.com/file/u1ujhzfwc3z08cb/njonjo.gmk
 

GMWolf

aka fel666
you never free your sprite.

you know you can draw surfaces without turning them into sprites?
Also that you can re-use a surface. You dont need to create a new one every time...
 
Top