Android sprite touch event gives error

99 Views Asked by At

I have the following code:

Sprite sPlayer = new Sprite(800 / 2, 480 / 2,
playerTextureRegion,
engine.getVertexBufferObjectManager()){
    @Override
    public boolean onAreaTouched(final TouchEvent tEvent, final float X,
    final float Y)
    {
        if ( tEvent.isActionDown() )
        // Some code
        return true;
    };
};

gameScene.registerTouchArea(sPlayer);
gameScene.setTouchAreaBindingOnActionDownEnabled(true);
gameScene.attachChild(sPlayer);
  1. When I run it, it gives me error and the app closes
  2. I see most people using gameScene.setTouchBindingEnabled(True) instead of gameScene.setTouchAreaBindingOnActionDownEnabled(true); but Eclipse doesn't recognize this one and I can't import any package for it. What exactly am I doing wrong?

Thanks in advance for your answers.

1

There are 1 best solutions below

0
On BEST ANSWER

According to your comment, you need to use the function runOnUiThread

YourActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
           Toast.makeText(YourActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    });

or, you can use the function toastOnUiThread :

YourActivity.toastOnUiThread(msg,Toast.LENGTH_SHORT);

where YourActivity is your activity in the game(just pass a reference to it)