【发布时间】:2019-01-02 01:03:02
【问题描述】:
我目前正在用 Java 制作 2.5D FPS 游戏。我的问题是当玩家与它们互动时门打开得太快了。我尝试了多种方法,例如使用计时器,但每次门立即完全打开。如何实现关闭状态和打开状态之间的平滑过渡?
这是我的 Door 类:
public class DoorBlock extends SolidBlock {
public boolean open = false;
public double openness = 0;
public double openLimit = 0.875;
public static boolean useDoor = false;
public int doorTimer = 0;
public DoorBlock() {
tex = 1;
}
public void tick() {
super.tick();
if (open)
openness += 0.2;
else
openness -= 0.2;
if (openness < 0)
openness -= openness;
if (openness > 1)
openness = 1;
if (openness < openLimit)
blocksMotion = true;
else
blocksMotion = false;
}
//If the player opens the door
public boolean use(StructureLoader level, Item item) {
openness = openLimit;
return true;
}
public boolean blocks(Entity entity) {
return true;
}
}
【问题讨论】:
-
tick是根据时间工作还是尽可能快地工作? -
是的,它基于时间。