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

GML Problem with using rotation values in draw_sprite_general when drawing partial sprites.

CraterHater

Member
Hey,

I have got a problem. I am trying to draw part of a sprite using the draw_sprite_general function. However, I also want to use rotational values to be able to rotate my sprite. Here is the code:
GML:
draw_sprite_general(sprite_index, image_index, 0, sprite_height-cycle_up_y, sprite_width, cycle_up_y, x, y+sprite_height-cycle_up_y, image_xscale, image_yscale, rotation_value, c_white, c_white, c_white, c_white, 0.95);
This code works just fine if the rotation_value == 0 but if it is anything else (and therefor has been rotated) the effect does not hold up. Any ideas how I can incorporate rotation into drawing a partial sprite?

Thanks!
 

SoapSud39

Member
When you modify your rotation, you also have to modify your position. That might include different things like sprite_xoffset and sprite_yoffset (because you're grabbing from a certain x and y of the image and it's drawing the partial image from the top-left corner of your segment) and any other x or y offset. So for your x and y values, you might declare a couple of local variables and for those add together a bunch of lengthdir_... values.
GML:
var px, py;
px = x + lengthdir_x(value1, angle1) + lengthdir_x(value2, angle2) + etc.
py = y + lengthdir_y(value1, angle1) + lengthdir_y(value2, angle2) + etc.
    //value1 and angle1 might be an x offset and rotation + 0 degrees
    //value2 and angle2 might be a y offset and rotation + 90 degrees
You'll have to mess around with your values and angles to get the desired visual effect, since every project is different. And to clarify what I mean with value1 and angle1, what I mean is that you'll have to do a separate set of lengthdir_x and lengthdir_y for every angle of offset you want to draw (so e.g. for sprite_xoffset you need a lengthdir_x and a lengthdir_y, and for sprite_yoffset you need another set, because y_offset is also 90 degrees offset). Alternatively, if you're good at trigonometry, this is here to help conceptually.
 
Top