Where i set touch effect when a spawn Srite are comming on the screen?
        Posted  
        
            by 
                shihab_returns
            
        on Game Development
        
        See other posts from Game Development
        
            or by shihab_returns
        
        
        
        Published on 2012-10-21T10:35:10Z
        Indexed on 
            2012/10/21
            11:22 UTC
        
        
        Read the original article
        Hit count: 226
        
I just create a scene where create a spawn spirit that comes from above screen height in Landscape mode. Now i want to remove spirits when i touch on it. I tried but seems the code not works and crashed also after a while. here is my code:
    /** TimerHandler for collision detection and cleaning up */
IUpdateHandler detect = new IUpdateHandler() {
    @Override
    public void reset() {
    }
    @Override
    public void onUpdate(float pSecondsElapsed) {
        Iterator<AnimatedSprite> targets = targetLL.iterator();
        AnimatedSprite _target;
        while (targets.hasNext()) {
            _target = targets.next();
            if (_target.getY() >= cameraHeight) {
                // removeSprite(_target, targets);
                tPool.recyclePoolItem(_target);
                targets.remove();
                Log.d("ok", "---------Looop Inside-----");
                // fail();
                break;
            }
        }
        targetLL.addAll(TargetsToBeAdded);
        TargetsToBeAdded.clear();
    }
};
/** adds a target at a random location and let it move along the y-axis */
public void addTarget() {
    Random rand = new Random();
    int minX = mTargetTextureRegion.getWidth();
    int maxX = (int) (mCamera.getWidth() - mTargetTextureRegion.getWidth());
    int rangeX = maxX - minX;
    Log.d("----point----", "minX:" + minX + "maxX:" + maxX + "rangeX:"
            + rangeX);
    int rX = rand.nextInt(rangeX) + minX;
    int rY = (int) mCamera.getHeight() + mTargetTextureRegion.getHeight();
    Log.d("---Random x----", "Random x" + rX + "Random y" + rY);
    target = tPool.obtainPoolItem();
    target.setPosition(rX, rY);
    target.animate(100);
    mMainScene.attachChild(target, 1);
    mMainScene.registerTouchArea(target);
    int minDuration = 2;
    int maxDuration = 32;
    int rangeDuration = maxDuration - minDuration;
    int actualDuration = rand.nextInt(rangeDuration) + minDuration;
    // MoveXModifier mod = new MoveXModifier(actualDuration, target.getX(),
    // -target.getWidth());
    MoveYModifier mody = new MoveYModifier(actualDuration,
            -target.getHeight(), cameraHeight + 10);
    target.registerEntityModifier(mody.deepCopy());
    TargetsToBeAdded.add(target);
}
    @Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
        final ITouchArea pTouchArea, final float pTouchAreaLocalX,
        final float pTouchAreaLocalY) {
    if (pTouchArea == target) {
        Toast.makeText(getApplicationContext(), "Yoooooooo",
                Toast.LENGTH_LONG).show();
    }
    return true;
}
** My question is where i implements IOnAreaTouchListener in My code. ? **
Thanks in Advance.
© Game Development or respective owner