Java 3D游戏:门开得太快

时间:2018-07-27 14:15:45

标签: java 3d

我目前正在用Java制作2.5D FPS游戏。我的问题是,当玩家与其互动时,门打开得太快。我尝试了多种方法,例如使用计时器,但是每次门立即完全打开时。如何在关闭状态和打开状态之间实现平滑过渡?

这是我的门课:

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;
    }
}

1 个答案:

答案 0 :(得分:0)

您正在将门设置为在此处立即打开

//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;
}