o_player Create
[spoiler]
/// @description Initalize
velocity_ = [0, 0];
gravity_ = 1;
jump_speed_ = 28;
max_velocity_ = [8, 32];
acceleration_ = 2.1;
direction_facing_ = dir.right;
// Spine
skeleton_animation_mix("IDLE", "WALK", 0.03);
skeleton_animation_mix("WALK", "IDLE", 0.03);
skeleton_animation_set("IDLE");
// Get the tilemap id
var layer_id = layer_get_id("Collisions");
collision_tile_map_id_ = layer_tilemap_get_id(layer_id);
enum player {
move,
}
enum dir {
right,
left
}
starting_state_ = player.move;
state_ = starting_state_;
// Sprite move lookup table
sprite_[player.move, dir.right] = s_player_right;
sprite_[player.move, dir.left] = s_player_left;
[/spoiler]
o_player Step
[spoiler]
/// @description Movement logic
depth = -y;
sprite_index = sprite_[state_, direction_facing_];
event_user(state_);
}
[/spoiler]
o_player User Event 0 - move_state
[spoiler]
/// @description move_state
// Get the input
var x_input = (keyboard_check(vk_right) - keyboard_check(vk_left)) * acceleration_;
// Vector variables
var vector2_x = 0;
var vector2_y = 1;
// Horizontal movement
velocity_[vector2_x] = clamp(velocity_[vector2_x]+x_input, -max_velocity_[vector2_x], max_velocity_[vector2_x]);
// Friction
if x_input == 0 {
velocity_[vector2_x] = lerp(velocity_[vector2_x], 0, .2);
}
// Gravity
velocity_[vector2_y] += gravity_;
// Move and contact tiles
move_and_contact_tiles(collision_tile_map_id_, 128, velocity_);
// Jumping
var on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
if on_ground {
// Jumping
if keyboard_check_pressed(vk_up) {
velocity_[vector2_y] = -jump_speed_;
}
} else {
// Control jump height
if keyboard_check_released(vk_up) && velocity_[vector2_y] <= -(jump_speed_/3) {
velocity_[vector2_y] = -(jump_speed_/3);
}
}
// Spine
if keyboard_check_pressed(vk_right) {
moving_ = true;
direction_facing_ = dir.right;
if skeleton_animation_get() != "WALK"
{
skeleton_animation_set("WALK");
}
}
if keyboard_check_pressed(vk_left) {
moving_ = true;
direction_facing_ = dir.left;
if skeleton_animation_get() != "WALK"
{
skeleton_animation_set("WALK");
}
}
if keyboard_check_released(vk_left) || keyboard_check_released(vk_right){
moving_ = false;
if skeleton_animation_get() != "IDLE"
{
skeleton_animation_set("IDLE");
}
}
[/spoiler]
get_direction_facing Script
[spoiler]
direction_facing_ = round(((_input_direction + 315) % 360) / 90);
[/spoiler]
Ok, currently the above code mostly works. I'm able to switch from left to right sprites, and the "IDLE" animation currently plays. Unfortunately, the "IDLE" animation constantly plays, and the "WALK" animation does't play at all.
I've tried multiple solutions, but keep coming up short...🙁.
Any help would be appreciated.
Thank you for your time.