🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

how to change a keyDown key from w to space?

Started by
2 comments, last by another2dgamedev 3 years, 7 months ago

I just want to know how to change the “w” in this line from w to spacebar. all help is appreciated.


if(keyPress.W && ground) {

this.yspd += -this.jspd;

}

Advertisement

go to keys.js file and change this:

document.onkeypress = function(event) {
	var key = (event.key).toUpperCase();
	...

to

document.onkeypress = function(event) {
	var key;
	if (event.keyCode == 32)
   	  	key = "SPACE";
	else
     	key = (event.key).toUpperCase();
     	...

save keys.js

NOTE: you will also need to change: document.onkeyup = …. to this new one (i leave it as an exercise for u to do ?)

then u can change:

if(keyPress.W && ground) {

this.yspd += -this.jspd;

}

to

if(keyPress.SPACE && ground) {

this.yspd += -this.jspd;

}

have fun ?

NOTE: you will also need to change: document.onkeyup = …. to this new one (i leave it as an exercise for u to do ?)

@ddlox

idk what to do, ive been trying for 2 hours…
@ddlox

This topic is closed to new replies.

Advertisement