N
Naal J.
Guest
Greetings all,
I've been dabbling with Game maker for about a month now and in a miraculous way, coding is actually starting to make sense to me, even to the point that I recently wrote some code without the use of any tutorials
However, I've come across an issue in which it seems to be multiple solutions to (in theory), but I do not think I'm using any of them the right way.
I have a snail like animation in which my player's way of moving is to slide across the floor. I have constructed the sprites in a manner that allows for the animation to move without moving and then I put a code in the animation end event that tells the sprites to move at the end of the animation which allows the sprites to line up seamlessly. Yet, when I press an arrow key to make the player move in another direction the sprite jerks in that direction in an unnatural way if the current sprite is not on a specific image index.
I am now trying to find a way to make the sprite change only when it has reached a specific image index on the current sprite to allow for a smooth transition. Here is the current code I was using to achieve this:
CREATE Event:
//varialbes
moving = false;
target_x = x;
target_y = y;
image_speed = 0.25;
sprite_previous = 0;
STEP Event:
//Move Player
if (target_x > x) { x += 32 } //right
if (target_x < x) { x -= 32 } //left
//Check Destination
if ( target_x == x && target_y == y ) {
moving = false;
sprite_previous = sprite_index
}
//Controls
if keyboard_check (vk_left)
{
if image_index > image_number -1
{
image_speed = 1;
sprite_index = spr_PlayerWalkLeft;
}
}
if keyboard_check (vk_right)
{
if image_index > image_number -1
{
image_speed = 1;
sprite_index = spr_PlayerWalkRight;
}
}
ANIMATION END Event:
if sprite_index = spr_PlayerWalkLeft {
target_x -= 32;
}
if sprite_index = spr_PlayerWalkRight {
target_x += 32;
}
This technique will only work if I press an arrow key at the exact moment the requested image is on the screen. If it's not on the screen, the player just continues with it's current animation. I want to make so that if you press the right arrow key while the player is going left, the sprites changes directions only when it reaches a SPECIFIC image_index. I think its also best that the player does not accept any further commands until it has successfully changed directions. Previously I tried to use alarms that go off when a key is pressed (which got extremely messy) and before that I experimented with switch statements, but I do not think I was using them correctly. Any push in the right direction would be highly appreciated. Let me know if more information is needed.
I've been dabbling with Game maker for about a month now and in a miraculous way, coding is actually starting to make sense to me, even to the point that I recently wrote some code without the use of any tutorials
However, I've come across an issue in which it seems to be multiple solutions to (in theory), but I do not think I'm using any of them the right way.
I have a snail like animation in which my player's way of moving is to slide across the floor. I have constructed the sprites in a manner that allows for the animation to move without moving and then I put a code in the animation end event that tells the sprites to move at the end of the animation which allows the sprites to line up seamlessly. Yet, when I press an arrow key to make the player move in another direction the sprite jerks in that direction in an unnatural way if the current sprite is not on a specific image index.
I am now trying to find a way to make the sprite change only when it has reached a specific image index on the current sprite to allow for a smooth transition. Here is the current code I was using to achieve this:
CREATE Event:
//varialbes
moving = false;
target_x = x;
target_y = y;
image_speed = 0.25;
sprite_previous = 0;
STEP Event:
//Move Player
if (target_x > x) { x += 32 } //right
if (target_x < x) { x -= 32 } //left
//Check Destination
if ( target_x == x && target_y == y ) {
moving = false;
sprite_previous = sprite_index
}
//Controls
if keyboard_check (vk_left)
{
if image_index > image_number -1
{
image_speed = 1;
sprite_index = spr_PlayerWalkLeft;
}
}
if keyboard_check (vk_right)
{
if image_index > image_number -1
{
image_speed = 1;
sprite_index = spr_PlayerWalkRight;
}
}
ANIMATION END Event:
if sprite_index = spr_PlayerWalkLeft {
target_x -= 32;
}
if sprite_index = spr_PlayerWalkRight {
target_x += 32;
}
This technique will only work if I press an arrow key at the exact moment the requested image is on the screen. If it's not on the screen, the player just continues with it's current animation. I want to make so that if you press the right arrow key while the player is going left, the sprites changes directions only when it reaches a SPECIFIC image_index. I think its also best that the player does not accept any further commands until it has successfully changed directions. Previously I tried to use alarms that go off when a key is pressed (which got extremely messy) and before that I experimented with switch statements, but I do not think I was using them correctly. Any push in the right direction would be highly appreciated. Let me know if more information is needed.