0

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.

manabreak
  • 4,719
  • 5
  • 32
  • 77

1 Answers1

3
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

Kumar Saurabh
  • 2,198
  • 5
  • 27
  • 38
  • well that's why i explained what exactly in my code is sprite and how to get the call back using overlap tester and getBoundingRectangle() so that its clear to the asker how he can get call back of touch on a Sprite – Kumar Saurabh Oct 22 '13 at 19:31
  • 1
    I guess as a beginner he doesn't even know where to get the touchPoint from. And also OverlapTester is no official class. And what about the exitTween()? Just confusing... – noone Oct 22 '13 at 19:32
  • Point taken and edited the answer.Thanks for your concern appreciated. Comments like these improve the standards of answer. Thanks for pointing me out. – Kumar Saurabh Oct 22 '13 at 19:42
  • @noone I'm not a beginner, but this was something I couldn't find in the official wiki. :) – manabreak Oct 23 '13 at 05:53