Aaron Finnessey
Member
For context, I'm working on a top-down, tactics-style game. While the player is in battle, they pull up a menu, and to move, the player selects "Move" from the menu. From there, a grid selector is created, and each time the selector moves, it adds a new point to a created path. When the player has chosen its desired path, they hit "Enter," and the path from the selector object is copied over to the player object, and the player object follows that path.
The issue arises when the player objects animates while on the path. When traveling either up or left, there is no issue, i.e. the player object gets the correct sprite from the sprite index based on its direction variable. However, when traveling either down or right, it continually flips between down/up or right/left, i.e. the player's direction variable flips between the correct value and its 180 degree partner (e.g. 270 -> 90-> 270, etc; 0 -> 180 -> 0, etc.). I have no variables set other than the reading of direction to choose the right sprite for the player object:
I've also tried it where the above code only checks against directions of exactly 0, 90, 180, and 270 to set the player sprite. It seems to be some interaction between the path and the direction variable, but even attempting to set the direction variable manually (i.e. using something like an "if (x > xprevious) {direction= 0}" statement has proved ineffectual. I imagine that this particular solution could create issues if the player was able to move all the time, but given the tactics movement system, the player can only move one direction and only one of the cardinal directions (0, 90, 180, or 270) at a time. I'm also aware of the semi-solution of using image_xscale *= -1 to switch between left and right sprites, but that would not solve the up/down issue, and given they share a common root issue, I haven't applied that just yet.
The issue arises when the player objects animates while on the path. When traveling either up or left, there is no issue, i.e. the player object gets the correct sprite from the sprite index based on its direction variable. However, when traveling either down or right, it continually flips between down/up or right/left, i.e. the player's direction variable flips between the correct value and its 180 degree partner (e.g. 270 -> 90-> 270, etc; 0 -> 180 -> 0, etc.). I have no variables set other than the reading of direction to choose the right sprite for the player object:
Code:
if (direction >= 316) || (direction <= 45) {sprite_index = spr_PlayerR;}
if (direction >= 46) && (direction <= 135) {sprite_index = spr_PlayerU;}
if (direction >= 136) && (direction <= 225) {sprite_index = spr_PlayerL;}
if (direction >= 226) && (direction <= 315) {sprite_index = spr_PlayerD;}