条件を機能させる方法がわかりません。条件に Keyboard.isKeyDown(//anykey) のようなものはありますか?
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
public class InputHandler {
public static boolean currentKeyState, previousKeyState;
public static void update() {
previousKeyState = currentKeyState;
if (//condition for keydown) {
currentKeyState = true;
} else {
currentKeyState = false;
}
}
public static boolean keyReleased() {
if (currentKeyState == true && previousKeyState == false) {
return true;
} else {
return false;
}
}
}
これが私が達成しようとしているもののC#バージョンです。Java で Keyboard.GetState() に似たメソッドはありますか?
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace Game.Controls
{
public class InputHandler
{
public KeyboardState currentKeyState;
public KeyboardState previousKeyState;
public InputHandler()
{
currentKeyState = new KeyboardState();
previousKeyState = new KeyboardState();
}
public void Update()
{
previousKeyState = currentKeyState;
currentKeyState = Keyboard.GetState();
}
public bool IsHeld(Keys key)
{
if (currentKeyState.IsKeyDown(key))
{
return true;
}
else
{
return false;
}
}
public bool IsReleased(Keys key)
{
if (currentKeyState.IsKeyUp(key) && previousKeyState.IsKeyDown(key))
{
return true;
}
else
{
return false;
}
}
public bool IsPressed(Keys key)
{
if (currentKeyState.IsKeyDown(key) && previousKeyState.IsKeyUp(key))
{
return true;
}
else
{
return false;
}
}
}
}