Question

A simple question: how could I pick up a sprite in libgdx? By this, I mean that when I click / touch the screen, it checks which (if any) sprite is clicked.

Was it helpful?

Solution

if(Gdx.input.justTouched())
    {
        cam.unproject(touchPoint.set(Gdx.input.getX(),Gdx.input.getY(), 0));
        if(Assets.playButton.getBoundingRectangle().contains(touchPoint.x,touchPoint.y ))
        {
// do what u want to do when image is touched
        }

Well Assets.playButton is actually a sprite type object

getBoundingRectangle() gives u the rectangle enclosed by the sprite

P.S:- touchPoint is a Vector3 type object

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top