Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.