0
私はLibgdxで一人称3Dゲームを作っています。すべてうまくいっています。私は、モバイルで実行しているとき、コントロールに小さな問題があります。Android:FirstPersonCameraController:Multitouch
方向ボタン(上、下、左または右)が最初に押された場合、画面の周りをドラッグ(回り込み)すると機能しません。最初に画面の周りをドラッグすると、両方が一緒に機能します。コードはそうKotlin
class InputController : FirstPersonCameraController {
private var gameRenderScreen: GameRenderScreen = GameRenderScreen()
private val forwardButton = TextButton("Forward", Gui.skin)
private val backwardButton = TextButton("Backward", Gui.skin)
private val leftButton = TextButton("Left", Gui.skin)
private val rightButton = TextButton("Right", Gui.skin)
private val jumpButton = TextButton("Jump", Gui.skin)
private val modeButton = TextButton("Mode", Gui.skin)
@JvmField
var isAdding = true
constructor(camera: Camera) : super(camera) {}
constructor(camera: Camera, gameRenderScreen: GameRenderScreen, stage: Stage) : super(camera) {
this.gameRenderScreen = gameRenderScreen
// create control
if (Gdx.app.type == Application.ApplicationType.Android || Gdx.app.type == Application.ApplicationType.iOS) {
var width: Float = Gdx.graphics.width/10f
var height: Float = Gdx.graphics.height/10f
forwardButton.setBounds(50f + width, 100f + (height * 2), width, height)
stage.addActor(forwardButton)
leftButton.setBounds(50f, 50f + height, width, height)
stage.addActor(leftButton)
rightButton.setBounds(50f + (width * 2), 50f + height, width, height)
stage.addActor(rightButton)
backwardButton.setBounds(50f + width, 10f, width, height)
stage.addActor(backwardButton)
jumpButton.setBounds(Gdx.graphics.width - width - 50f, 50f + height, width, height)
stage.addActor(jumpButton)
modeButton.setBounds(Gdx.graphics.width - width - 50f, 100f + (height * 2), width, height)
stage.addActor(modeButton)
}
//Todo fix this as it stops touching working
val multiplexer = InputMultiplexer()
multiplexer.addProcessor(this)
multiplexer.addProcessor(stage)
Gdx.input.inputProcessor = multiplexer
}
override fun keyDown(keycode: Int): Boolean {
if ((keycode == Input.Keys.SPACE || jumpButton.isPressed) && gameRenderScreen.isJump == false && gameRenderScreen.jumping == 0.0f) {
gameRenderScreen.isJump = true
}
if (keycode == Input.Keys.ENTER || modeButton.isPressed) {
isAdding = !isAdding
}
return super.keyDown(keycode)
}
// Called from Render loop
fun updateControls() {
if (Gdx.app.type == Application.ApplicationType.Android || Gdx.app.type == Application.ApplicationType.iOS) {
if (forwardButton.isPressed) {
keyDown(Input.Keys.W)
} else {
keyUp(Input.Keys.W)
}
if (backwardButton.isPressed) {
keyDown(Input.Keys.S)
} else {
keyUp(Input.Keys.S)
}
if (leftButton.isPressed) {
keyDown(Input.Keys.A)
} else {
keyUp(Input.Keys.A)
}
if (rightButton.isPressed) {
keyDown(Input.Keys.D)
} else {
keyUp(Input.Keys.D)
}
if (modeButton.isPressed) {
isAdding = !isAdding
} else {
}
if (jumpButton.isPressed && gameRenderScreen.isJump == false && gameRenderScreen.jumping == 0.0f) {
gameRenderScreen.isJump = true
} else {
}
}
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
hasMoved = true
return super.touchDragged(screenX, screenY, pointer)
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
hasMoved = false
return super.touchDown(screenX, screenY, pointer, button)
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (hasMoved == false) {
gameRenderScreen.getObject(screenX, screenY)
}
return super.touchUp(screenX, screenY, pointer, button)
}
companion object {
fun width(): Int {
return Gdx.graphics.width
}
fun height(): Int {
return Gdx.graphics.height
}
var hasMoved: Boolean = false
}
}