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

Legacy GM Spinning the mouse around the player lags the whole game

A

AwesomeAlvin

Guest
The game I am making is a top down shooter, where the player sprite rotates to the mouse position.
Whenever I spin the mouse quickly around the player, the game lags.
Here's what it looks like:


I've tried commenting out the code that rotates the player, but still no luck.
I've also tried getting rid of the view object that follows the mouse and player.

Any ideas?

thanks!
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Does disabling rotation towards the mouse remove the lag? If so, could you show your current code for that?
 
A

AwesomeAlvin

Guest
Set room_speed=60

Else your code will only catch the mouse pos for 30 frames. But your mouse move faster.
The room speed is already at 60. Sorry, forgot to mention in OP.

Does disabling rotation towards the mouse remove the lag? If so, could you show your current code for that?
Unfortunately it doesn't...
Here's the code anyways:
Player Object:
Code:
// Step Event
ang = point_direction(x,y, mouse_x, mouse_y);

// Draw Event
draw_sprite_ext(sprite_index, 1, x, y, 1, 1, ang, c_white, 1);
Gun/Arms Object:
Code:
// Step Event
image_angle = point_direction(x,y,mouse_x,mouse_y);
The reason why the player has it in the draw event, is because my game is physics based where the collision is all handled by just the player object. So image_angle does not work.

I had previous build of my game where it wasn't physics based, and the rotation is just like the gun/arms, and the lag still occurred.
 
A

AwesomeAlvin

Guest
Ah yeah I think it was just my PC, thanks for testing! I restarted my computer, and it works normally now. Not sure what was causing it, but I did do some video editing, but it was closed when I tested the game.
I've got another minor issue that involves lag. The game will just randomly stutter. It's not that big of a stutter, but it annoys me quite a bit. Can you see it on your end, or is it just me again?
 

sp202

Member
Works fine for me, but what's concerning is that I only get 44 or so frames per second. I was using a integrated laptop graphics card but that's beside the point; you've got so many wall objects in the game and you're not limiting how many are being rendered at a time.

The generally recommended approach is to deactivate the objects outside the view. However, there's a cheeky approach that might just work seeing as you're making a top down game. Draw all the wall objects onto a surface, turn the surface into a sprite and destroy all the wall objects. Now you have a single sprite with a whole room's worth full of walls. You'll of course need to use precise collision checking so I don't know what it'll do to CPU and memory usage at larger room sizes but it's worth a try.

By the way, why does killing insects in the game produce bones?
 
  • Like
Reactions: 607
A

AwesomeAlvin

Guest
Works fine for me, but what's concerning is that I only get 44 or so frames per second. I was using a integrated laptop graphics card but that's beside the point; you've got so many wall objects in the game and you're not limiting how many are being rendered at a time.

The generally recommended approach is to deactivate the objects outside the view. However, there's a cheeky approach that might just work seeing as you're making a top down game. Draw all the wall objects onto a surface, turn the surface into a sprite and destroy all the wall objects. Now you have a single sprite with a whole room's worth full of walls. You'll of course need to use precise collision checking so I don't know what it'll do to CPU and memory usage at larger room sizes but it's worth a try.

By the way, why does killing insects in the game produce bones?
Each side of the wall is just one object that I stretched out. About the technique you said, my collisions are based on the box2d physics, so I'm not sure if using the precise collision method on the sprite works or not.

For the bones, logically it makes no sense, but in the game it's the currency. You can access the shop by pressing B after each wave :)
 
Top