Search code examples
cocos2d-android

How to Detect the CCSprite Touchevent getBoundingbox equals of CCTouches


I am new to COCOS2d. I am using ccsprite with animation as a button. Now i am struggle to detect the CCTouches and CCsprite getbounding box are equals for click event.


Solution

  • From this way you can achieve what you need and write this code in CCtouches___() :

     ArrayList<CCSprite> animation= new ArrayList<CCSprite>();
     CGPoint  location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY()));
    
     for (CCSprite target : animation){
         if(CGRect.containsPoint((target.getBoundingBox()), location)){
         //here what you want
         }