Cocos2d x 如何在Cocos2Dx中处理触摸
我的问题是,当触摸屏幕上的任何位置时,精灵就不可见了。但我想这样做,精灵应该是无形的,只有当我点击精灵Cocos2d x 如何在Cocos2Dx中处理触摸,cocos2d-x,Cocos2d X,我的问题是,当触摸屏幕上的任何位置时,精灵就不可见了。但我想这样做,精灵应该是无形的,只有当我点击精灵 bool CharacterSelection::ccTouchBegan(CCTouch* pTouch, CCEvent* pEvent { CCTouch* touch; CCPoint tap = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView()); Goa
bool CharacterSelection::ccTouchBegan(CCTouch* pTouch, CCEvent* pEvent
{
CCTouch* touch;
CCPoint tap = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
GoatSprite* goat;
goat = (GoatSprite*) goatSpriteObject;
if(touch){
tap = touch->getLocation();
}
if(goat->boundingBox().containsPoint(tap)){
goat->setVisible(false);
}
return true;
}
如果代码中有错误,很抱歉。我觉得你的代码很奇怪
CCEvent*pEvent
pTouch
输入,无需创建新的CCTouch*touch代码>
if(touch)
而您什么也没做,这将是pTouch
if(touch)
条件cocos2d::CCPoint p = pTouch->getLocation();
cocos2d::CCRect rect = goat->getBoundingBox();
if(rect.containsPoint(p))
{
// you touched it
}