1
I am creating a game in Javascript. This is my first contact with the language and also the development of games.
Going straight to the question, I can walk and jump in the game, but when I’m walking and jumping, the game does not perform anything, stops walking and also does not jump (the game does not freeze, if you release the keys and press again it makes the functions of walking and jumping normally).
These functions check the pressed key and perform the function:
function jump(event){
if(event.keyCode == 38){
cube.pula();
}
}
function walk(){
if(event.keyCode == 39){
cube.right();
}
if(event.keyCode == 37){
cube.left();
}
}
These are the functions (skip, right, left). The functions are inside an object called cube:
pula: function(event){
if(this.jps < 2){
this.jps++;
this.v = -this.fp;
}else if(this.y == 250){
this.jps = 0;
this.jps++;
this.v = -this.fp;
}
},
right: function(){
if(this.x <= width-64){
this.x += this.force;
}
},
left: function(){
if(this.x >= 15){
this.x += -this.force;
}
},
I put the code in Codepen as requested. I also put an html comment explaining the variables.
We need a little more information to help you, for example: Where are the functions called
jump
andwalk
? What do the variables meanjps
,v
,fp
,force
, And where are they being used? You can guess what they do, but it’s a lot easier if you explain, and the chances of being able to help you increase x)– GBrandt