+ 3
Please help me to find error
https://code.sololearn.com/WQu2fu7akH20/?ref=app My code doesn't work well..... Please help me to find error
3 Antworten
+ 2
https://code.sololearn.com/W6X88Jq7SL2H/?ref=app
The mouseup and mousedown event listener are not working on mobile.
I changed to use two buttons with onclick.
Also, this game, I have fixed for others before. Where is the origin of this code? Please add a link or description mentioning the origin, thanks.
+ 2
as Gordon said this will not work on a touch device (no mouse). The onclick method he used still doesnt work for me(ios has a weird issue with onclick not being used on a button element). I used ontouchdown and ontouchend to get it to work on ios.
+ 1
I'm sorry that I can't just help you simply because I can't understand your code fully, but gravity should work like this:
let downforce = 0;
let upforce = 0;
y_pos = the users y position
//gets an onclick trigger
function go_up(){
upforce = 2; //amount to go up
downforce = 0;
}
//gets checked every frame
//let this run before drawing the square to avoid weird y positions
function pullDownByGravity(){
if(y_pos > bottom y (= canvas height)){
y_pos = bottom y;
upforce = 0;
downforce = 0;
}
if(y_pos < bottom y){
y_pos -= upforce;
upforce -= downforce;
downforce += 0.2; //let the force (at some point) be greater than the upforce to go down
}
}