Ah! I think i see what you're trying to achieve. (TL;DR at bottom)
like what
@ColdaDog says, if your player is symmetrical, you only need to make half the sprites.
say you make 5 sprites at 45 degrees (could be more, such at 18 sprites each at 10 degrees), a quick way to change the sprite would be using maths instead of if statements:
lets imagine you have created 5 sprites facing:
Code:
- south -> image index = 0
- south east -> image index = 1
- east -> image index = 2
- north east -> image index = 3
- north -> image index = 4
in this format they become easy to produce an easy procedure to handle them
(k̶n̶i̶f̶e̶ angle goes in, g̶u̶t̶s̶ image_index comes out!)
we will need 2 variables:
Code:
var angle = [any angle] + 90 // any input angle
var spacing = [angle spacing] // in out case it is 45 degrees
(i add 90 to the angle to make angle 0 face downwards - it makes calculations a lot simpler as everything can be handled in once swift case instead of two split cases)
from there we will need to restrict the angle to be within 0 and 180, however in a strange way
if the angle is 190, we do not set the angle to 180 degrees...
instead we want to set it to 170 degrees to make it symmetrical
this is done by taking away 180 degrees, which gives you the remaining angle.
you then want to take away
that remaining angle from 180 degrees.
this should only be done if the angle is greater than 180 degrees, like so:
Code:
if (angle > 180)
{
angle = 180-(angle-180);
image_xscale = -1; // changes the xscale so the player faces left
}
else
{
image_xscale = 1; // face right
}
Now we have the angle in the correct format, we can
FINALLY change the image index (yayyy)! ;o;
This is done by getting the value of the rounded down (floored) value of the angle divided by the spacing:
Code:
image_index = floor(angle/spacing); // sets the image index
if the angle input is 270 (down), the image index will be 0
TL;DR - all the code together which should help you solve your problem:
Code:
//# create a script - scr_player_axis (or something else you would prefer)
var angle = argument0+90; // input angle
var spacing = argument1; // spacing
if (angle > 360) angle-=360; // this makes it so the angle doesn't overflow
if (angle > 180)
{
angle = 360-angle; // this is the same as 180-(angle-180), it's just faster! ;w;
image_xscale = -1;
}
else
{
image_xscale = 1;
}
image_index = floor(angle/spacing); // change image index!
// end
now using:
will set the player's sprite to be facing downwards!
and using:
will make the player face south-west!
I don't know if i helped but I found it entertaining to solve a problem like this ;0
(i may have complicated things LOL i'm sorry ;^; )
(ps.
in action )
##### QUICK EDIT:
I found a bug in which it resulted in negative angles.
I added a check of if (angle>360) to take away 360 degrees, e.g. 370 degrees get canceled down to 10 degrees!