How to detect a touch on transparent area of an image in a (libgdx) stage?

Posted by Usman on Game Development See other posts from Game Development or by Usman
Published on 2012-11-18T09:46:35Z Indexed on 2012/11/18 11:28 UTC
Read the original article Hit count: 259

Filed under:
|
|

Can some one please help to detect a touch on an image which I am using as an actor in a stage. The image is actually a long diagnol brush which has plenty of transparent area. The problem is when I touche the transparent area of the brush image it is also triggering the clicklistener of the image. I need the click listener should only be called when the finger actually touched the visible image not the area which is empty.

I am using libgdx-0.9.4 libraries. Here is my simple piece of code.

import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;


Image brushImg = new Image(ImageCache.getTexture("brush"));
brushImg.width = mStage.width()*0.75f;
brushImg.height = mStage.height()*0.75f;

brushImg.setClickListener(new ClickListener() {

@Override
public void click(Actor actor, float x, float y) {          
    SoundFactory.play("brush");   
}

© Game Development or respective owner

Related posts about java

Related posts about android