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

SOLVED Animating from 4 to 8 directions, closes app without error on run

I

iAnzenGenki

Guest
Hello! I was following along with Shaun's ARPG and have decided to make the jump from 4 to 8 directions for my player sprite with the code he shared in his tutorial. I've changed the sprite from 32 frames to 64, 8 frames in each direction starting with Right and working around counter clock-wise as was shown and the idle sprite is changed from 4 to 8 to reflect this. I then went into the animation code to work in the additional directions...

GML:
function PlayerAnimateSprite(){

var _cardinalDirection = round(direction/45);
var _totalFrames = sprite_get_number(sprite_index) / 8;
image_index = localFrame + (_cardinalDirection * _totalFrames);
localFrame += sprite_get_speed(sprite_index) / FRAME_RATE;

if (localFrame >= _totalFrames)
    {
    animationEnd = true;
    localFrame -= _totalFrames;
    } else animationEnd = false

}
I've changed the direction rounding from 90 to 45 as to work in the 4 additional cardinal directions and the sprite_get_number was changed from 4 to 8 because I now have 8 directional groups in the sprite. I can avoid the crash by using a number less than 8, but the animation flickers between conflicting groups. I haven't changed anything in the movement script in the player step event although I have a feeling I need to...

Code:
keyLeft = keyboard_check(vk_left) || keyboard_check(ord("A"));
keyRight = keyboard_check(vk_right) || keyboard_check(ord("D"));
keyUp = keyboard_check(vk_up) || keyboard_check(ord("W"));
keyDown = keyboard_check(vk_down) || keyboard_check(ord("S"));
keyFire = mouse_check_button(1)

inputDirection = point_direction(0,0,keyRight - keyLeft,keyDown - keyUp);
inputMagnitude = (keyRight - keyLeft != 0) || (keyUp - keyDown != 0);

hSpeed = lengthdir_x(inputMagnitude * speedWalk, inputDirection);
vSpeed = lengthdir_y(inputMagnitude * speedWalk, inputDirection);

PlayerCollision();

var _oldSprite = sprite_index;

if (inputMagnitude !=0)
{
    direction = inputDirection;
    sprite_index = spriteRun;
} else sprite_index = spriteIdle;
if (_oldSprite != sprite_index) localFrame =0

PlayerAnimateSprite()
oh my head is spinning, but my sprite is not o_O
 
Last edited by a moderator:
I

iAnzenGenki

Guest
Are you sure you don't want to assign image_index after you're done manipulating localFrame?
I think it irons out either way and I had it working the same way with 4 directions. I only changed the 2 values and that's where things went down hill.

EDIT: @Nidoking ok idk why I didn't try it earlier just to make sure but I did what you suggested and surprise it worked šŸ˜… My question is why did it work with the values with 4 directions before? It's still baffling...
 
Last edited by a moderator:
Top