0

In Order to make the sprite(canon) touch and react(firing bullet) to that touch in cocos2d-android, i have set this.setIsTouchEnabled(true); in constructor, and in ccToouchesBegan() added the below code

@Override
public boolean ccTouchesBegan(MotionEvent event)    
{  

    canon1 = CCSprite.sprite("android.png");
     canon1.setPosition(CGPoint.ccp(10, 60));
     canon1.setScale(1f);
    addChild(canon1);

    CGRect canon1Rect = CGRect.make(canon1.getPosition().x - (canon1.getContentSize().width/2),
            canon1.getPosition().y - (canon1.getContentSize().height/2),
            canon1.getContentSize().width,
            canon1.getContentSize().height);

    // Choose one of the touches to work with
    CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(10,60));

return;
}

so when touched on sprite(cannon) bullets must fire out, but here the touch is not working.

DD.
  • 973
  • 2
  • 10
  • 32
  • possible duplicate of [How to make the sprite respond to the touch on it in cocos2d android](http://stackoverflow.com/questions/17400522/how-to-make-the-sprite-respond-to-the-touch-on-it-in-cocos2d-android) – Morion Jul 01 '13 at 10:41

1 Answers1

0

I hope this will help you.

public boolean ccTouchesEnded(MotionEvent event) {
        CGPoint location = CCDirector.sharedDirector().convertToGL(
                CGPoint.ccp(event.getX(), event.getY()));
        if (CGRect.containsPoint((newGame1.getBoundingBox()), location)) {

            newGame();

        }

        return super.ccTouchesEnded(event);
    }
Bebin T.N
  • 2,539
  • 1
  • 24
  • 28