• 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 Making a sprite shake...

F

Freedom2Fight

Guest
...using draw_sprite_ext. When the player object gets hurt - that sort of shake.

I have a couple of ideas on how to do this but I need some help.

Code:
draw_sprite_ext( sprite, subimg, x, y, xscale, yscale, rot, colour, alpha );
I'm thinking of assigning x and y with variable like shake or wooble. Then I'll write something in the step event that will change the values of shake. I'm thinking of using random functions but I'd prefer it not to be random.

Any help would be appreciated.
 

Bingdom

Googledom
Code:
draw_sprite_ext( sprite, subimg, x+random_range(-shake,shake), y+random_range(-shake,shake), xscale, yscale, rot, colour, alpha );
 
  • Like
Reactions: Yal

Roderick

Member
Code:
draw_sprite_ext( sprite, subimg, x+random_range(-shake,shake), y+random_range(-shake,shake), xscale, yscale, rot, colour, alpha );
If you want something smoother, use
Code:
x + sin(current_time / 1000) *5
This makes it oscillate smoothly side to side.

It will go from center to either extreme, or back again, in 1 second, for a total of a 4 second cycle. To make it faster, reduce the 1000 (current_time is in milliseconds).

sin produces a result from -1 to 1, so multiplying by 5 makes the object move 5 pixels away at the most. Change this number to make it move more or less.
 
F

Freedom2Fight

Guest
If you want something smoother, use
Code:
x + sin(current_time / 1000) *5
This makes it oscillate smoothly side to side....
I like this. Thanks, Roderick.

If anyone else have a way of shaking sprites please share. It'll help not just me but also the people who might come across this thread trying to achieve the ..err.. shake.
 
Top