GML Spine / Sprite Look-up Table ?

L

Lithalean

Guest
o_player Create
Code:
/// @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;

o_player Step
Code:
/// @description Movement logic

depth = -y;
sprite_index = sprite_[state_, direction_facing_];
event_user(state_);

}

o_player User Event 0 - move_state
Code:
/// @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");
      }
}

get_direction_facing Script
Code:
direction_facing_ = round(((_input_direction + 315) % 360) / 90);

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.
 
Last edited by a moderator:

TheouAegis

Member
It's not simple laziness, it's memory optimization. That said, your argument concerning left-right differences is valid.
 

sylvain_l

Member
It's not simple laziness, it's memory optimization
not only memory optimisation, also time optimisation.
Drawing or creating those additionnal animations take time too. (even if using skeletal animation and you can speed up using mirror piece in spine for example: part is just reorganising the z index to invert the order but that won't be enough you'll need to redraw/mirror objects, because that can be ok for a sword, to just use the same/mirror for left or right, but for a shield for example, that doesn't work ). That way you can manage to have both: left/right walk/anim. but you can also have left/right handed anim.

Original o_player Create
The problem with that is I generally view that as lazy programing, and just plain bad practice.
it's not about laziness, it's about efficiency. Compromizing on that left/right mirror mean you can invest time/effort/ressource on other thing, like a particle/light effect or polish more the responsivness of the player character or give you time to develop additionnal level/quest.
Under your ressource/time limit, what will give the best experience for the player with your game ?
 
L

Lithalean

Guest
@TheouAegis
TheouAegis said:
it's memory optimization.
I can respect this answer, and for a majority of my enemies i'll use image_xscale for that exact reason. Although for the player (main character), I truly feel, it should have a dedicated sprite per direction, because it should also be detailed enough to require it.

@sylvain_l
TheouAegis said:
time optimization...efficiency...what will give the best experience for the player with your game ?"
Again, all good points. As I said above, i'll be using image_xscale for a majority of enemies, for those reasons as well.

Looking at my original comments again... I could of worded things better, and not been as closed minded and judgmental when I'm so new to the programing side of things.
I've edited my original post with progress and removed assumptive statements. My apologies if I offended anyone.
As always,
Thank you for your time.
 
Last edited by a moderator:

TheouAegis

Member
You can match your Sprites without using data structures, although most people aren't comfortable doing it that way. But you just have to essentially convert all your sprite assignments into algorithms. Instead of saying using a particular Sprite index, you say they use a variable indexed by your current state or whatever.
 
Top