B
bhoyle753
Guest
btw happy new year!
thank you, you too. I have it working now so the up direction and the down direction sprite stay consistent when you press up or down but the left and right ones change still change (Ill have to fix those now if I can). I'll do my best to make them work the same way and see if it is what you need. I might record a quick clip and post it on youtube also to show you what it looks like if you can implement it right and it works if I get it working just right.btw happy new year!
Nice! sure i can see what i can do with itI got it working awesome. I think it's what you need. It locks the direction and saves it on all four axis in your "major" direction.
I am very very happy with the result. I'll see if I can adapt it to be used without a grid.
I just tried it with the analog stick though and it doesn't get the same result.
Very unfortunate. Not sure how to fix that at the moment. I'll show you what I have soon though.
If you end up switching the controller movement to the dpad it will work with the controller though and you wont have to do any adjustment. I'm not sure if that's ok with you though.
Ok great. I'll have to just post the version I have and then simplify it later so you don't have to make grids if it's possible.Nice! sure i can see what i can do with it
yes indeed it isn't totally necessary to have analog control but it makes gameplay feel much more precise and enjoyable to me anywaysOk great. I'll have to just post the version I have and then simplify it later so you don't have to make grids if it's possible.
I'll also try to figure out how to make it work with the analog. (It makes it so you have to get it -precisely- on 0,90,180,270 degrees in order for the sprite to change but at least we know what the problem is there if you really want analog control. I'm sure it's fixable)
aw thats unfortunate, and yeah sprinting do you know how to do it?hmm darn. I did notice one thing it still plays the first idle frame in each direction. instead of skipping right to the first walking sprite on keypress. It's very close. I might have to just post what I have now and work with you on it later if i can.
sprinting seems like a good idea.
// create event
characterWalkSpeed=3;
// define x_frame in terms of sprite width and height 0 for first, 32 for second, etc.
x_frame = 0;
//y_frame 64 starts the character facing down (second box down in sprite sheet)
// adjust if you want a different direction on spawn
y_frame = 64;
// make sure this is the same as your starting sprite direction
// but I don't think it matters much 0=right 90=up 180=left 270=down
playerFacing= 270;
// using the sprite sheet, collisions get messed up for some reason, these are used to fix it
// the bottom of the draw event calculates this offset and replaces
// the sprite draw location to the proper player location (+ half sprite width and height)
playerCollisionAdjust_X=16;
playerCollisionAdjust_Y=16;
// step event
right_key = keyboard_check(vk_right) or (keyboard_check(ord("D")));
left_key = keyboard_check(vk_left) or (keyboard_check(ord("A")));
up_key = keyboard_check(vk_up) or (keyboard_check(ord("W")));
down_key = keyboard_check(vk_down) or (keyboard_check(ord("S")));
// define deadzone of gamepad_axis_value(controller_ID, horizontal axis) to be 0.2
// abs means absolute value (always positive if analog stick is tilted)
if (abs(gamepad_axis_value(0,gp_axislh)) > 0.2
or abs(gamepad_axis_value(0,gp_axislv)) > 0.2)
{
left_key = abs(min(gamepad_axis_value(0,gp_axislh),0))
right_key = max(gamepad_axis_value(0,gp_axislh),0);
up_key = -max(gamepad_axis_value(0,gp_axislv),0);
down_key= -abs(min(gamepad_axis_value(0,gp_axislv),0));
}
hspeed = (right_key-left_key) * characterWalkSpeed;
vspeed = (down_key-up_key) * characterWalkSpeed;
// horizontal collision
if (place_meeting(x+hspeed, y, obj_wallBasic))
{
while (!place_meeting(x+sign(hspeed), y, obj_wallBasic))
{
x = x + sign(hspeed);
}
hspeed = 0;
}
// vertical collision
if (place_meeting(x, y+vspeed, obj_wallBasic))
{
while (!place_meeting(x, y+sign(vspeed), obj_wallBasic))
{
y = y + sign(vspeed);
}
vspeed = 0;
}
// draw event
var anim_length = 4;
var frame_size = 32;
var anim_speed = 7;
// down
if (vspeed > 0) and abs(hspeed)==0
{
playerFacing = 270;
y_frame = 64;
if right_key or left_key
{y_frame = 64;}
}
if (vspeed == 0 and playerFacing == 270)
{x_frame = 0}
// up
if (vspeed < 0) and abs(hspeed)==0
{
playerFacing = 90;
y_frame = 32;
if right_key or left_key
{y_frame = 32;}
}
if (vspeed == 0 and playerFacing == 90)
{x_frame = 0}
//l eft
if (hspeed < 0) and abs(vspeed)==0
{
playerFacing = 180;
y_frame = 96;
if up_key or down_key
{y_frame = 96;}
}
if (hspeed == 0 and playerFacing == 180)
{x_frame = 0}
// right
if (hspeed > 0) and abs(vspeed)==0
{
playerFacing = 0;
y_frame = 128;
if up_key or down_key
{y_frame = 128;}
}
if (hspeed == 0 and playerFacing == 0)
{x_frame = 0}
//variables adjusting improper collision box
var xx = x-playerCollisionAdjust_X;
var yy = y-playerCollisionAdjust_Y;
// this draws a sprite "part" from the sheet using these arguments (sprite,subimg, left, top, width, height, x, y)
// x and y are replaced with the collision offsets because it messes up for some reason
draw_sprite_part(spr_player_grid, 0 , floor(x_frame)*frame_size, y_frame, frame_size, frame_size, xx, yy)
// 60 represents the frames per second of your game in anim_speed/60, change if different.
if (x_frame < anim_length +1) {x_frame += anim_speed/60}
else {x_frame = 1}
// delete the "//" from the line below this one to show the collision box of your character
//draw_rectangle_color(bbox_left,bbox_top, bbox_right, bbox_bottom, c_yellow,c_yellow,c_yellow,c_yellow, true)
You are welcome, most of all I'm just really proud we could figure out the whole "direction lock" thing together and get it working in all four directions.wow this is great, thanks a lot!
// create event
//add this variable to your create event
sprintTimer = 3;
// step event
// add this at the bottom of your step event
if (keyboard_check(vk_shift) and sprintTimer > 0)
{
characterWalkSpeed = 6;
sprintTimer -= room_speed/3600
}
if (!keyboard_check(vk_shift) or sprintTimer < 0)
{
characterWalkSpeed = 3;
sprintTimer += room_speed/3600 *(1/3)
}
if(sprintTimer >=3)
{
sprintTimer = 3;
}
//DrawGUI
//optional, add a DrawGUI to your character
// and then add these lines so you can see your sprint timer
//you can also add it to your camera DrawGUI since it directly references the character
draw_set_colour(c_white);
// x, y, string (usually put in drawGUI)
draw_text(20,20,"sprintTimer: " +string(obj_player.sprintTimer))
if (sprintTimer <= 0)
{
characterWalkSpeed = 3;
}
var anim_length = 4;
var frame_size = 32;
var anim_speed = 3;
// down
if (vspeed > 0) and abs(hspeed)==0
{
playerFacing = 270;
y_frame = 64;
if right_key or left_key
{y_frame = 64;}
}
if (vspeed == 0 and playerFacing == 270)
{ x_frame = 0 }
// up
if (vspeed < 0) and abs(hspeed)==0
{
playerFacing = 90;
y_frame = 32;
if right_key or left_key
{y_frame = 32;}
}
if (vspeed == 0 and playerFacing == 90)
{x_frame = 0}
//left
if (hspeed < 0) and abs(vspeed)==0
{
playerFacing = 180;
y_frame = 96;
if up_key or down_key
{y_frame = 96;}
}
if (hspeed == 0 and playerFacing == 180)
{x_frame = 0}
// right
if (hspeed > 0) and abs(vspeed)==0
{
playerFacing = 0;
y_frame = 128;
if up_key or down_key
{y_frame = 128;}
}
if (hspeed == 0 and playerFacing == 0)
{x_frame = 0}
//variables adjusting improper collision box
var xx = x-playerCollisionAdjust_X;
var yy = y-playerCollisionAdjust_Y;
// this draws a sprite "part" from the sheet using these arguments (sprite,subimg, left, top, width, height, x, y)
// x and y are replaced with the collision offsets because it messes up for some reason
draw_sprite_part(spr_player_grid, 0 , floor(x_frame)*frame_size, y_frame, frame_size, frame_size, xx, yy)
// 60 represents the frames per second of your game in anim_speed/60, change if different.
if (abs(vspeed) or abs(hspeed)>0)
{ //prevents the idle animation from being played if the character is moving
if x_frame ==0
{x_frame = 1}
//determines when the animation is finished (when it gets to a number 1 higher)
if x_frame = anim_length+1
{x_frame = 1}
// animated the sprite when the character is moving (multiply by a number to increase speed)
x_frame += anim_speed/60
}
//draw_rectangle_color(bbox_left,bbox_top, bbox_right, bbox_bottom, c_yellow,c_yellow,c_yellow,c_yellow, true)
// draw event
var anim_length = 4;
var frame_size = 32;
var anim_speed = 4;
// down
if (vspeed > 0) and abs(hspeed)==0
{
playerFacing = 270;
y_frame = 64;
if right_key or left_key
{y_frame = 64;}
}
if (vspeed == 0 and playerFacing == 270)
{ x_frame = 0 }
// up
if (vspeed < 0) and abs(hspeed)==0
{
playerFacing = 90;
y_frame = 32;
if right_key or left_key
{y_frame = 32;}
}
if (vspeed == 0 and playerFacing == 90)
{x_frame = 0}
//left
if (hspeed < 0) and abs(vspeed)==0
{
playerFacing = 180;
y_frame = 96;
if up_key or down_key
{y_frame = 96;}
}
if (hspeed == 0 and playerFacing == 180)
{x_frame = 0}
// right
if (hspeed > 0) and abs(vspeed)==0
{
playerFacing = 0;
y_frame = 128;
if up_key or down_key
{y_frame = 128;}
}
if (hspeed == 0 and playerFacing == 0)
{x_frame = 0}
//variables adjusting improper collision box
var xx = x-playerCollisionAdjust_X;
var yy = y-playerCollisionAdjust_Y;
// this draws a sprite "part" from the sheet using these arguments (sprite,subimg, left, top, width, height, x, y)
// x and y are replaced with the collision offsets because it messes up for some reason
draw_sprite_part(spr_player_grid, 0 , floor(x_frame)*frame_size, y_frame, frame_size, frame_size, xx, yy)
// 60 represents the frames per second of your game in anim_speed/60, change if different.
if (abs(vspeed) or abs(hspeed)>0 )
{ //prevents the idle animation from being played if the character is moving
if x_frame ==0
{x_frame = 1}
//determines when the animation is finished (when it gets to a number 1 higher)
if x_frame == anim_length+1
{x_frame = 1}
// animated the sprite when the character is moving (multiply by a number to increase speed)
if( x_frame+(anim_speed/60)<anim_length+1)
{x_frame += anim_speed/60}
else{x_frame = 1}
}
//draw_rectangle_color(bbox_left,bbox_top, bbox_right, bbox_bottom, c_yellow,c_yellow,c_yellow,c_yellow, true)
// step event
// sprite direction lock
// down
if (vspeed > 0) and abs(hspeed)==0
{
playerFacing = 270;
obj_player.sprite_index = spr_player_down;
if right_key or left_key
{obj_player.sprite_index = spr_player_down;}
}
if (vspeed == 0 and playerFacing == 270)
{obj_player.sprite_index = spr_player_down_idle}
// up
if (vspeed < 0) and abs(hspeed)==0
{
playerFacing = 90;
obj_player.sprite_index = spr_player_up;
if right_key or left_key
{ obj_player.sprite_index = spr_player_up;}
}
if (vspeed == 0 and playerFacing == 90)
{obj_player.sprite_index = spr_player_up_idle;}
//left
if (hspeed < 0) and abs(vspeed)==0
{
playerFacing = 180;
obj_player.sprite_index = spr_player_left;
if up_key or down_key
{obj_player.sprite_index = spr_player_left;}
}
if (hspeed == 0 and playerFacing == 180)
{obj_player.sprite_index = spr_player_left_idle;}
// right
if (hspeed > 0) and abs(vspeed)==0
{
playerFacing = 0;
obj_player.sprite_index = spr_player_right;
if up_key or down_key
{obj_player.sprite_index = spr_player_right;}
}
if (hspeed == 0 and playerFacing == 0)
{obj_player.sprite_index = spr_player_right_idle;}
This is perfect, im glad there are people like you to help guide me through these challenges, thanks and good luck with your game too, i hope it goes as planned!Here is the final project file in case you don't catch the link in my last comment. I think this one is solved. It doesn't glitch and it keeps your movement.
Finally perfect. https://www.dropbox.com/s/ojes82u10c57h0t/bhoyleGame_Final_perfect.rar?dl=0 Thanks friend.
Also, heres the sprites if you want to use them (or for anyone else reading this)
be sure to name the ones with 4 with _strip4 suffix when you import them (or _strip# however many frames you have if you use other sprites) and it will auto import the animations.
Moral of the story: just use the sprite editor and sprite_indexes instead of using a grid. It seems like it works better and it 100% easier.
On a side note, I think the version we made using the grid actually does work I just had the camera following a copy of the player that I hadn't put in the room so it was making a weird glitch with animations.
Sorry about that. I think I'd still prefer to do it without a grid personally. Good luck with your game.