I’m diving into libgdx and used their pattern sport as a place to begin.
I additionally added a touchpad to maneuver the bucket. That was type of simple and labored flawless.
My further concept was to make the touchpad disappear when not touching/clicking the display screen and be proven once more when you contact it. Mainly to provide the participant the liberty to determine the place he needs to have the touchpad positioned on the display screen.
Watching this recording it really works fairly good however clearly I do not wish to make it observe the mouse continuously. So I attempted to make the touchpad (which is an actor on my stage) invisible. As quickly as I do this, I’m dropping the contact occasion being forwarded to the touchpad. See this recording.
My preliminary concept was to not have the pad continuously observe the mouse pointer (as I wish to assist contact screens in some unspecified time in the future too). So the perfect method I attempted however did not implement was so as to add the touchpad on any “down” occasion and and “transfer” occasion afterwards is dealt by the touchpad however that doesn’t work. The stage retains the first goal of the enter occasion and the touchpad is just not knowledgeable about something.
I attempted it with an InputMultiplexer however failed with it as nicely…
Any concepts?
My major class:
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.InputListener
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
import com.badlogic.gdx.utils.ScreenUtils
class MyGame : ApplicationAdapter() {
personal lateinit var pad: Touchpad
personal lateinit var stage: Stage
personal lateinit var digital camera: OrthographicCamera
override enjoyable create() {
// create the digital camera and the SpriteBatch
digital camera = OrthographicCamera().apply {
setToOrtho(false, 800f, 480f)
}
stage = Stage()
stage.addListener(object : InputListener() {
override enjoyable touchDown(occasion: InputEvent?, x: Float, y: Float, pointer: Int, button: Int): Boolean {
println("tdown")
pad.isVisible = true
return tremendous.touchDown(occasion, x, y, pointer, button)
}
override enjoyable mouseMoved(occasion: InputEvent?, x: Float, y: Float): Boolean {
println("mmoved")
if (!pad.isVisible) {
pad.x = x - pad.width / 2f
pad.y = y - pad.top / 2f
}
return tremendous.mouseMoved(occasion, x, y)
}
override enjoyable touchUp(occasion: InputEvent?, x: Float, y: Float, pointer: Int, button: Int) {
println("tup")
pad.isVisible = false
tremendous.touchUp(occasion, x, y, pointer, button)
}
})
Gdx.enter.inputProcessor = stage;
val padBackground = TextureRegionDrawable(Texture(Gdx.recordsdata.inside("pad_circle.png")))
val padThumb = TextureRegionDrawable(Texture(Gdx.recordsdata.inside("pad_thumb.png")))
pad = Touchpad(10f, Touchpad.TouchpadStyle(padBackground, padThumb))
pad.addListener(object : InputListener() {
override enjoyable enter(occasion: InputEvent?, x: Float, y: Float, pointer: Int, fromActor: Actor?) {
println("pad enter")
pad.isVisible = true
tremendous.enter(occasion, x, y, pointer, fromActor)
}
override enjoyable exit(occasion: InputEvent?, x: Float, y: Float, pointer: Int, toActor: Actor?) {
pad.isVisible = false
println("pad exit")
tremendous.exit(occasion, x, y, pointer, toActor)
}
})
pad.isVisible = false
stage.addActor(pad)
}
override enjoyable render() {
ScreenUtils.clear(0f, 0f, 0.2f, 1f)
digital camera.replace()
stage.act(Gdx.graphics.deltaTime)
stage.draw()
}
override enjoyable dispose() {
}
}