S
Direction = "DOWN";
if (Direction == "DOWN"){ }
if (Direction == "DOWN") {
if (Yaxis == 0) {
sprite_index = D_p_IDLE;
}
// ...
}
// @description Inisloiz
XAxis = 0; // left/right movement
YAxis = 0; // up/down movement
Speed = 2; // how fast we move
Direction = DOWN;
Action = IDLE;
View[RIGHT,IDLE] = v_p_right;
View[UP,IDLE] = v_p_up;
View[LEFT,IDLE] = v_p_left;
View[DOWN,IDLE] = v_p_down;
/// @description
XAxis = keyboard_check(vk_right) - keyboard_check(vk_left);
YAxis = keyboard_check(vk_down) - keyboard_check(vk_up);
if (XAxis > 0)
Direction = RIGHT;
else if (XAxis < 0)
Direction = LEFT;
if (YAxis > 0)
Direction = DOWN;
else if (YAxis < 0)
Direction = UP;
var _direction = point_direction(0, 0, XAxis, YAxis);
var _length = Speed * (XAxis != 0 || YAxis != 0);
//show_debug_message(string(_length));
XAxis = lengthdir_x(_length, _direction);
YAxis = lengthdir_y(_length, _direction);
if (place_meeting(x+XAxis, y, OBJ_Colishion))
{
while(!place_meeting(x+sign(XAxis), y, OBJ_Colishion))
{
x += sign(XAxis);
}
XAxis = 0;
}
x += XAxis;
if (place_meeting(x, y+YAxis, OBJ_Colishion))
{
while(!place_meeting(x, y+sign(YAxis),OBJ_Colishion))
{
y += sign(YAxis);
}
YAxis = 0;
}
y += YAxis;
//Chang the sprit
sprite_index = View[Direction,Action];
// movment code
if (Direction == "DOWN") {
if (YAxis == 0) {
sprite_index = D_p_IDLE;
}
//...
}
but in my scripts i also have and they look like this
Macros//:
[CODE]// direction
#macro RIGHT 0
#macro UP 1
#macro LEFT 2
#macro DOWN 3
// action
#macro IDLE 0
idle = 1;
walking = 0;
up = 3;
right = 2;
down = 1;
left = 0;
Action = idle;
Direction = down;
View[1,3] = v_p_upIdle;
View[1,2] = v_p_rightIdle;
View[1,1] = v_p_downIdle;
View[1,0] = v_p_leftIdle;
View[0,3] = v_p_upWalking;
View[0,2] = v_p_rightWalking;
View[0,1] = v_p_downWalking;
View[0,0] = v_p_leftWalking;
if (keyboard_check(vk_up) || keyboard_check(vk_right) || keyboard_check(vk_down) || keyboard_check(vk_left)) {
Action = walking;
if (keyboard_check(vk_up)) {Direction = up;}
if (keyboard_check(vk_right)) {Direction = right;}
if (keyboard_check(vk_down)) {Direction = down;}
if (keyboard_check(vk_left)) {Direction = left;}
} else {Action = idle}
sprite_index = View[Action, Direction];
// direction
#macro RIGHT 0
#macro UP 1
#macro LEFT 2
#macro DOWN 3
// action
#macro IDLE 0
image_speed = 0.5; // the animation will be half speed
image_speed = 2; // the animation will be double speed