How to Detect the CCSprite Touchevent getBoundingbox equals of CCTouches

孤街浪徒 提交于 2019-12-23 06:14:16

问题


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.


回答1:


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
     }


来源:https://stackoverflow.com/questions/17963332/how-to-detect-the-ccsprite-touchevent-getboundingbox-equals-of-cctouches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!