Search code examples
libgdxkotlin

How to implement input handling in libgdx with ananymous inner class in kotlin


I want to implement below example from libgdx wiki in Kotlin

enter image description here

Here is my attempt:

Gdx.input.inputProcessor = InputAdapter() {
        override fun touchDown(x: Int, y: Int, pointer: Int, button: Int): Boolean {
            // My code
            return true
        }
    }

but I definitely do something wrong


Solution

  • Should be:

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