• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Character button operation

U

uni00

Guest
Good evening. I'm Japanese so I use Google Translate.
For some reason, you have to change the character from keyboard operation to on-screen button operation. I used the keyboard to move and change the sprite, but I have to display the move button on the screen to make it for the sootphone.
I converted the if statement that was in the step statement to the with statement and put it in the button, but the sprite did not change, there were many restrictions and it was strict.
So I thought that while the right button is being pressed using the global variable, it should be set to true and put in the argument of the if statement, but increase the five global variables by combining the up, down, left and right buttons and the button that picks up the item. I am worried that may have a bad effect on memory.
How can I convert the right move item in this step statement into a button operation?

GML:
--step(o_player1)--

//rightmove↓
if(keyboard_check(vk_right))
{
    if(place_meeting(x,y,o_spider_floor)){
    hspeed=1/2;
    }
    else{
  hspeed =1;
    }
  sprite_index = spr_player1_walk;
  image_xscale = 1.5;
  if(!audio_is_playing(sound0))
{
audio_play_sound(sound0,1,false);
}
  with(o_lamp_spr){
  sprite_index=spr_lamp;
                  }
}//rightmove↑
else if(keyboard_check(vk_left))
{
      if(place_meeting(x,y,o_spider_floor)){
    hspeed=-1/2;
    }
    else{
  hspeed =-1;
    }
   sprite_index = spr_player1_walk;
   image_xscale =-1.5;
     if(!audio_is_playing(sound0))
{
audio_play_sound(sound0,1,false);
}

     with(o_lamp_spr){
  sprite_index=spr_lamp;
                     }
}
else {
    sprite_index = spr_player1;
    hspeed=0;

      with(o_lamp_spr){
  sprite_index=spr_lamp;
                      }
     }

if(image_xscale=1.5&&vspeed=3){
with(o_lamp_spr){
x=o_player1.x+27;
y=o_player1.y+17;
}
}
else if(image_xscale=-1.5&&vspeed=3){
with(o_lamp_spr){
x=o_player1.x-27;
y=o_player1.y+17;
}
}

audio_listener_position(x, y, 0);
GML:
--step(o_right)--

var cx = camera_get_view_x(view_camera[0]);
var cy = camera_get_view_y(view_camera[0]);


x= cx+55;
y=cy+197;
 

Yal

🐧 *penguin noises*
GMC Elder
You can use "virtual keys" to have a screen region that generates keyboard events. The game will treat them just like normal key presses, so you don't need to change the game logic.
 
Top