GameMaker: Studio

GameMaker: Studio

İstatistiklere Bak:
8 Directional Movement with WASD Keys
I'm newer to Gamer Maker Studio, and I have a little bit of knowledge on how to code, but I can find no tutorials that show how to do 8 Directional Movement with the WASD Keys.

And I have tried to replace 8 Directional Code for the Arrow keys to the WASD keys, but to no avail.

Please submit any help you have, anything helps.
< >
9 yorumdan 1 ile 9 arası gösteriliyor
What do you plan on doing? DnD or GML?
For GML:
if keyboard_check(ord('A'))
{x-=5}

This will move the object 5 pixels to the left, if I remember correctly.
İlk olarak Albcatmastercat tarafından gönderildi:
What do you plan on doing? DnD or GML?
For GML:
if keyboard_check(ord('A'))
{x-=5}

This will move the object 5 pixels to the left, if I remember correctly.

Yes, but I need continuous movement, not pixels every tap of a button. Sorry, needed to be more specific.
if keyboard_check(ord('A')) is correct for that
for tapping is keyboard_check_pressed
İlk olarak Wesley Ronald tarafından gönderildi:
if keyboard_check(ord('A')) is correct for that
for tapping is keyboard_check_pressed

Well, both just go left 5 pixels, then stop. I don't know if its a glitch or what.
I know how to do it.

Create a Step Event.

Then Copy Paste the following.

playerSpeed = 5;

//Shortcuts for keypresses
MOVELEFT = keyboard_check(ord('A'));
MOVERIGHT = keyboard_check(ord('D'));
MOVEUP = keyboard_check(ord('W'));
MOVEDOWN = keyboard_check(ord('S'));

//Move Player
if (MOVELEFT && x > sprite_width/2)
{
x -= playerSpeed;
}

if (MOVERIGHT && x < room_width - sprite_width/2)
{
x += playerSpeed;
}

if (MOVEUP && y > room_height/2)
{
y -= playerSpeed;
}

if (MOVEDOWN && y < room_height - sprite_width/2)
{
y += playerSpeed;
}

:steamhappy:
İlk olarak hammy tarafından gönderildi:
I know how to do it.

Create a Step Event.

Then Copy Paste the following.

playerSpeed = 5;

//Shortcuts for keypresses
MOVELEFT = keyboard_check(ord('A'));
MOVERIGHT = keyboard_check(ord('D'));
MOVEUP = keyboard_check(ord('W'));
MOVEDOWN = keyboard_check(ord('S'));

//Move Player
if (MOVELEFT && x > sprite_width/2)
{
x -= playerSpeed;
}

if (MOVERIGHT && x < room_width - sprite_width/2)
{
x += playerSpeed;
}

if (MOVEUP && y > room_height/2)
{
y -= playerSpeed;
}

if (MOVEDOWN && y < room_height - sprite_width/2)
{
y += playerSpeed;
}

:steamhappy:
change...
if (MOVEUP && y > room_height/2)
to....
if (MOVEUP && y > sprite_height/2)
:cozynms:
One way to do it for continous movement without constant key presses is to use the built in variables hspeed and vspeed. These act like the built in variable speed but only on their axis.
if(keyboard_check(ord("A"))) hspeed=-5;if(keyboard_check(ord("D"))) hspeed=5; if(keyboard_check(ord("W"))) vspeed=-5;if(keyboard_check(ord("S"))) vspeed=5;
En son The Winter Bud tarafından düzenlendi; 2 Ara 2021 @ 13:44
< >
9 yorumdan 1 ile 9 arası gösteriliyor
Sayfa başına: 1530 50