[英]Jumping Doesn't Work Slick2D
I have this code, and when I press space, it goes all weird.我有这个代码,当我按下空格键时,它变得很奇怪。 I have tested it, and
jump()
is being called when I press space.我已经测试过了,当我按下空格键时会调用
jump()
。 I don't receive an error for anything.我没有收到任何错误。
public static void update(int delta)
{
if (!grounded && !jumping)
y += gravity;
if (y > 275)
{
grounded = true;
jumpTime = 0;
}
if (jumping && jumpTime < maxJumpTime)
{
y -= jumpPower;
jumpTime++;
}
if (jumpTime > maxJumpTime)
{
jumping = false;
jumpTime = 0;
}
if (jumping)
{
grounded = false;
}
}
public static void jump(int power)
{
if (grounded)
{
jumpPower = power;
grounded = false;
jumping = true;
} else
return;
}
The variables are:变量是:
x
y
gravity (1)
jumpTime
maxJumpTime (5)
jumpPower (1).
Without a better idea of what "going weird" means, I would assume it has something to do with you labeling your methods as static.如果没有更好地了解“变得奇怪”的含义,我认为这与您将方法标记为静态有关。 I would think the compiler would get mad when you try and access a non-static variable (x and y) from a static context.
我认为当您尝试从静态上下文访问非静态变量(x 和 y)时,编译器会生气。 Jumping and updating seem like things you want to be individual to the object not something that will affect all of the objects.
跳转和更新似乎是您希望对对象单独进行的事情,而不是会影响所有对象的事情。
I would recommend giving this a read: http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html我建议阅读一下: http : //docs.oracle.com/javase/tutorial/java/javaOO/classvars.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.