detachSelf question...

  ... discussions about development with the GLES1 branch of AndEngine.

detachSelf question...

Postby elkaiser_77 » Fri Mar 30, 2012 1:44 pm

Hi all,

i've got a class (Mole.class, extends Sprite) for a game. In this class i implement onAreaTouched and onManagedUpdate:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.         public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
  3.                 SmashTheMole.vScore += 1;
  4.                 SmashTheMole.delMoleInMap(pX, pY);
  5.                 detachSelf();
  6.                 return false;
  7.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.         protected void onManagedUpdate(float pSecondsElapsed) {
  3.                 // TODO Auto-generated method stub
  4.                 super.onManagedUpdate(pSecondsElapsed);
  5.                
  6.                 secOnMole += 2 * pSecondsElapsed;
  7.                
  8.                 if (!isVisible() && secOnMole > 5) {
  9.                         setVisible(true);
  10.                 } else if (isVisible() && secOnMole > 7) {
  11.                         SmashTheMole.delMoleInMap(pX, pY);
  12.                         SmashTheMole.vLoses += 1;
  13.                         detachSelf();
  14.                 }
  15.         }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


When i touch the mole, he disappears but the area continue managing the touch event...
And, if i allow the mole to escape, then i touch the area and it counts for my score...

Anyone can help me?

i had got resetPosition() instead of detachSelf() before, but i want to "destroy" the mole, not change him position.
clearUpdateHandlers() don't work for me and i don't know how to try now... :(

Thank you
elkaiser_77
 
Posts: 26
Joined: Thu Mar 15, 2012 11:56 am

Re: detachSelf question...

Postby Primadawn » Mon Apr 02, 2012 12:24 am

You need to unregister the touch area - call scene.unregisterTouchArea(sprite);
Primadawn
 
Posts: 414
Joined: Fri Sep 23, 2011 3:28 am


Return to GLES1

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], patrinandrey and 18 guests