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...
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...
oh my head is spinning, but my sprite is not
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
}
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()
Last edited by a moderator: