1. BoundingBox : CCNode的一个属性,返回精灵的边界。
CCNode‘s attribute , return the side of sprite
2. getContentSize :每一个精灵都被看成是一个矩形,具有长和宽,单位是point,返回的是矩形的大小。
every sprite is regarded as a rectangle,includes length and width,unit is point,return the size of rectangle.
3. setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne); //表示允许触摸 indicate we can touch
4. void registerWithTouchDispatcher(void);//注册触摸
bool ccTouchBegan(CCTouch* pTouch,CCEvent* pEvent); //触摸开始,注意返回类型,如果返回false,就不用写下面三个函数
void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);//触摸滑动
void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);//触摸结束
void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);//触摸取消,例如中途来点
开启触摸
在需要开启触摸的地方加入就行,例如init里面
- bool Hello::init()
- {
- setTouchEnabled(true);
- return true;
- }
- void Hello::registerWithTouchDispatcher()
- {
- CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
- }
- bool Hello::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
- {
- CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
- CCLOG("touch began, touchpoint is %f", touchpoint);
- return true; //true表示继续响应CCTouchMove,CCTouchEnd,CCTouchCancalled,false表示不响应。
- }
- void Hello::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
- {
- CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
- CCLOG("touch move, touchpoint is %f", touchpoint);
- }
6、实现ccTouchEnded
- void Hello::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
- {
- CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
- CCLOG("touch end, touchpoint is %f", touchpoint);
- }
7、实现ccTouchCancalled
- void Hello::ccTouchCancalled(CCTouch *pTouch, CCEvent *pEvent)
- {
- CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
- CCLOG("touch end, touchpoint is %f", touchpoint);
- }