displacement of an object in game maker

0

when executing the code in the create event in game maker studio 2:

sprite_index = Spr_Pacman_Right; //imagen del sprite pacman

image_speed = 0;//velocidad de imagen

image_index = 0;//indice de la imagen

 v = 0; // variable de velocidad

all right but when executing the step event code:

if (keyboard_check(vk_right)){
direction = 0;
speed = v;
}

if (keyboard_check(vk_left)){
direction = 180;
speed = v;
}

if (keyboard_check(vk_up)){
direction = 90;
speed = v;
}

if (keyboard_check(vk_down)){
direction = 270;
speed = v;
}

the object on the screen does not move

    
asked by Irving Frias 29.12.2017 в 20:10
source

2 answers

1

It is because you have to indicate in which axis you want the character to advance, if you want to advance to the right, indicate that add the value of the variable v (velocity) to the X axis, for example:

if (keyboard_check(vk_right)){
direction = 0;
x += v; // moverse a la derecha
} 

in the case of the left is the same, but subtracting X

if (keyboard_check(vk_left)){
direction = 180;
x -= v;
}

Up and down you must work the Y axis

if (keyboard_check(vk_up)){
direction = 90;
y += v // moverse abajo
}

Finally, if "v" is given a value of 0, nothing will happen; It must be 1 or more.

Greetings.

    
answered by 02.04.2018 в 00:49
-1

You have two errors:

  • In CREATE variable V can not be zero, expected >0 Asignale a number to the variable.

    V=5; //Aquí se especifica la velocidad.
    
  • You are missing a code in the event STEP ;

  • The code would be this: speed=0 put it at the beginning of the step in this way:

    speed=0
    
    if (keyboard_check(vk_right)){
    direction = 0;
    speed = v;
    }
    
    if (keyboard_check(vk_left)){
    direction = 180;
    speed = v;
    }
    
    if (keyboard_check(vk_up)){
    direction = 90;
    speed = v;
    }
    
    if (keyboard_check(vk_down)){
    direction = 270;
    speed = v;
    }
    
        
    answered by 24.05.2018 в 21:14