• 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 Help with draw_sprite_general

H

Harper

Guest
I am so confused... When I use draw_sprite_general it draws my sprite up and to the right by half the sprite width and height. I assume it's because GMS2 thinks the sprite origin is elsewhere, but I can't figure it out.

DRAW:
Code:
draw_self();

get_controls();
if(key_test) distance--;

draw_sprite_general(sprite_index, 0, distance, 0, sprite_width, sprite_height, x, y, 1, 1, image_angle, c_white, c_white, c_white, c_white, 1);
If I use any other draw function, it slaps the sprite on top of the original like it's supposed to, but I need to use a function that alters the angle it's drawn and the part of the sprite that is drawn. The variable distance starts at the value 0 in the create code, and doesn't change until I hit the assigned key, so it's not the problem.

I tried using lengthdir functions but I have no way of getting the angle that I need because I'm drawing a sprite not creating an instance...

 
R

robproctor83

Guest
You must have a bad variable, try hard coding values instead of variables until you get it how you want and then replace them one by one with variables.

To draw at an angle is one of the parameters of the function, rot, you can just change that.
 
H

Harper

Guest
I just found the problem, although I don't know the solution. When using draw_sprite_general or draw_sprite_part, it's rotational axis is set to the top left of the sprite instead of the origin like it should be. This means when it's drawn, it's drawn from it's origin and can only be rotated around the origin so I have no clue how to solve this problem.
 
H

Harper

Guest
Ah I see, I haven't done this before but it may work

https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sprites/sprite_set_offset.html

This should let you set the origin in code, so give that a shot.
I tried
Code:
sprite_set_offset(spr_player, 64, 64);
right before my draw_sprite_general, but no luck :/, it didn't budge at all. I think this function just affects the object/instances sprite, not any sprites that are being drawn to the screen :(.
 
Try drawing your draw_sprite_general at these coordinates:

x+_c*_x+_s*_y
y-_s*_x+_c*_y

where x,y is the position of your other sprite. _c and _s are dcos(angle) and dsin(angle), angle being the corresponding argument to draw_sprite_general, and _x and _y are:

_x = _left - sprite_get_xoffset(some_sprite);
_y = _right - sprite_get_yoffset(some_sprite);

_left and _right being the corresponding arguments to draw_sprite_general.
 
H

Harper

Guest
Ah yea that makes sense actually because draw_sprite_part changes the x/y offset to 0,0 as well. So, what you have to do to solve this is rotate with the general function and then secondarily move the sprite around using lengthdir. You can find a possible working solution posted here by the amazin YellowAfterLife, but you may need to tweak it:

https://forum.yoyogames.com/index.p...ssible-when-using-draw_sprite_part_ext.41836/
Thank you so much! I was able to modify what YellowAfterLife used in the forum like you said and it works perfectly!
Here's my modified code for future confused coders, it is a very long line of code...:
Code:
draw_sprite_general(sprite_index, 0, distance, 0, sprite_width, sprite_height, x - lengthdir_x(sprite_width / 2, image_angle) - lengthdir_x(sprite_width / 2, image_angle - 90), y - lengthdir_y(sprite_height / 2, image_angle) - lengthdir_y(sprite_height / 2, image_angle - 90), 1, 1, image_angle, c_white, c_white, c_white, c_white, 1);
 

Old2DGuy

Member
...I was able to modify what YellowAfterLife used in the forum like you said and it works perfectly!
Here's my modified code for future confused coders, it is a very long line of code...:
After spending quite some time trying to figure this out, my Google searches finally lead me to this solution and it works great!
Thank you! :)
 
Top