Cocos2d设置精灵触摸范围

void HelloWorld::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent){
    CCTouch *touch = (CCTouch *)pTouches->anyObject();
	CCPoint beginLoc = touch->locationInView();
	beginLoc = CCDirector::sharedDirector()->convertToGL(beginLoc);
    
    CCRect rect = pSprite1->boundingBox();          //得到精灵的矩形框
    int x = rect.origin.x;                          //得到矩形框的左下角x坐标
    int y = rect.origin.y;                          //得到矩形框的左下角x坐标
    int w = rect.size.width;                        //得到矩形框的宽
    int h = rect.size.height;                       //得到矩形框的高
    
    rect = CCRect(210, 130, 20, 20);                //重新设置精灵的矩形框x坐标为210,Y坐标为130,宽w为20,高h为20    
   CCLog("%d==%d==%d==%d",x,y,w,h);
    if(CCRect::CCRectContainsPoint(rect, beginLoc)){
       plabel1->setVisible(true);
    }
}


你可能感兴趣的:(Cocos2d-x)