如何在 libgdx 中使用 kotlin 中的匿名内部 class 实现输入处理
How to implement input handling in libgdx with ananymous inner class in kotlin
我想在 Kotlin
中实现 libgdx wiki 中的以下示例
这是我的尝试:
Gdx.input.inputProcessor = InputAdapter() {
override fun touchDown(x: Int, y: Int, pointer: Int, button: Int): Boolean {
// My code
return true
}
}
但我肯定做错了
应该是:
Gdx.input.inputProcessor = object : InputAdapter() {
override fun touchDown(x: Int, y: Int, pointer: Int, button: Int): Boolean {
// My code
return true
}
override fun touchUp(x: Int, y: Int, pointer: Int, button: Int): Boolean {
// My code
return true
}
}
我想在 Kotlin
中实现 libgdx wiki 中的以下示例这是我的尝试:
Gdx.input.inputProcessor = InputAdapter() {
override fun touchDown(x: Int, y: Int, pointer: Int, button: Int): Boolean {
// My code
return true
}
}
但我肯定做错了
应该是:
Gdx.input.inputProcessor = object : InputAdapter() {
override fun touchDown(x: Int, y: Int, pointer: Int, button: Int): Boolean {
// My code
return true
}
override fun touchUp(x: Int, y: Int, pointer: Int, button: Int): Boolean {
// My code
return true
}
}