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

SOLVED Animation get the game lag

S

sefi331

Guest
Hi guys, I have a really weird problem. I use a portal animation in my game. When the object that has the portal animation in his step and draw event got created - it makes the game stuck and lag for a second, but only when the object is first created. After that the object got destroyed and recreated again with no lag at all - everything go smoothly. I tried to change the code so the object will get created when the game first start and not be destroyed at all (control the animation creation by variables) and it still not working. The object using the famous approach script in his step event and draw event. Did someone got any idea why it happens? Thank you.
 
S

sefi331

Guest
Sure. Forgot to mention the room uses physics

if global.blackscreen_freeze = false
{
if scale_in = true
{
xScale = approach (xScale,1.2,0.03); // (start, end, shift);
yScale = approach (yScale,1.2,0.03); // (start, end, shift);
frame = frame + 40/room_speed
}
if scale_out = true
{
xScale = approach (xScale,0.2,0.03); // (start, end, shift);
yScale = approach (yScale,0.2,0.03); // (start, end, shift);
frame = frame + 40/room_speed
}

if fadeout = true
{alpha = approach(alpha,0,0.02);} // (start, end, shift); =======================> fade
}



draw:

draw_sprite_ext(s_portal, frame, x, y+10 ,xScale/5 * facing, yScale/5, angle, color, alpha)
 
Last edited by a moderator:

Let's Clone

Member
How many sprite images are you looking through? it seems your frame variable has the potential to be a decently large index_number.
 
How big are your sprites? Do they all fit in one texture page? Have you seperated them into their own Texture Group?

A delay when first creating an instance is sometimes caused by GMS loading the texture pages.
 
S

sefi331

Guest
1409 X 729. So I need to reduce the images size? is there another way?
 
Is that the size of a single frame of your sprite I take it? That is indeed quite large, it would require several texture pages if you have 50 frames all of that size, depending on your settings and that would explain the lag when drawing the sprite for the first time.

If you are only building for PC, I think you can have a maximum page size of 8192x8192 pixels, can't check at the moment. That would reduce the total number of texture pages, but some older graphics cards won't handle textures that big. And you would still probably get lag when loading them anyway.

Reducing your sprite by half and then scaling it up when drawing would be something you could try. Try to make the sprite evenly divisible by 2 first though, or you will get scaling artifacts.

What is the sprite that big for? That size is going to almost fill the screen for most common resolutions.
 
S

sefi331

Guest
I reduced the size and deleted few frames and it seems to work ok. Thanks
 
Top