【问题标题】:Java 3D game: Door opens too fastJava 3D 游戏:门打开太快
【发布时间】: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 是根据时间工作还是尽可能快地工作?
  • 是的,它基于时间。

标签: java 3d


【解决方案1】:

你在这里设置的门立即打开

//If the player opens the door
public boolean use(StructureLoader level, Item item) {
    openness = openLimit;
    return true;
}

修改它以触发tick函数中的打开机制:

//If the player opens the door
public boolean use(StructureLoader level, Item item) {
    open = true;
    return true;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 2012-09-15
    相关资源
    最近更新 更多