[英]What am I doing wrong in my jumping script?
我正在构建2D平台游戏。 而且我还没有编写用于跳跃等所有内容的脚本,但是我有可以向各个方向移动的基本脚本:
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '38') {
if (yVel <= 4){
yVel += speed;
}else{
yVel = yVel
}
y -= yVel;
}
else if (e.keyCode == '40') {
if (yVel <= 4){
yVel += speed;
}else{
yVel = yVel
}
y += yVel;
}
else if (e.keyCode == '37') {
if (xVel <= 4){
xVel += speed;
}else{
xVel = xVel
}
x -= xVel;
}
else if (e.keyCode == '39') {
if (xVel <= 4){
xVel += speed;
}else{
xVel = xVel
}
x += xVel;
}
结果应该是脚本,如果需要的话,它可以让您对角移动,但是我所得到的是,例如,当您按下向上键时,它上升了,但是当您按下任何其他按钮时,例如,向右,那么它会停止向上运动,并且只会向右移动。 这里有项目代码: https : //repl.it/@MarkelL/Break-It这是项目本身: https : //break-it--markell.repl.co/
解释将不胜感激。 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.