문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top