registerWithTouchDispatcher & ccTouchBegan 备忘 true or false
2014-02-15 16:02
525 查看
原文链接:http://my.oschina.net/u/184773/blog/64596
cocos2d-x中要想实现触摸就要实现CCTargetedTouchDelegate或CCStandardTouchDelegate协议中的一个。
继承CCTargetedTouchDelegate,你不用关心触摸点,协议会自动分配。
然后你需要注册一下,即
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);第一个参数为代理目标,第二个为优先级,数值越小,触摸点就会先传递。
第三个为是否要吞掉触摸点,ture的话就是在ccTouchBegan返回true后触摸点就不再传递。
然后在节点释放或不再需要的时候取消注册,CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
最后就是要实现需要的四个方法中的一个或多个:
bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);注意返回值是bool型,返回true则触摸点不再传递,false的话继。
void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);
这种主要用在一些单个节点中,如触摸一个精灵,然后让他放大。 当有许多子节点,如layer或都需要用到多点就要用到以下方法了。
继承CCStandardTouchDelegate协议。layer默认。只需要以下操作
在初始化或进入的时候加上 setTouchEnabled(true);
实现四个方法中的一个或多个。如:
void MutiTouchTestLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) //返回值是void
{
CCSetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
{//这里你要手动处理每一个点!
CCTouch* pTouch = (CCTouch*)(*iter);
CCPoint location = pTouch->locationInView();
}
}
其队三个函数类似!
cocos2d-x中要想实现触摸就要实现CCTargetedTouchDelegate或CCStandardTouchDelegate协议中的一个。
继承CCTargetedTouchDelegate,你不用关心触摸点,协议会自动分配。
然后你需要注册一下,即
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);第一个参数为代理目标,第二个为优先级,数值越小,触摸点就会先传递。
第三个为是否要吞掉触摸点,ture的话就是在ccTouchBegan返回true后触摸点就不再传递。
然后在节点释放或不再需要的时候取消注册,CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
最后就是要实现需要的四个方法中的一个或多个:
bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);注意返回值是bool型,返回true则触摸点不再传递,false的话继。
void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);
这种主要用在一些单个节点中,如触摸一个精灵,然后让他放大。 当有许多子节点,如layer或都需要用到多点就要用到以下方法了。
继承CCStandardTouchDelegate协议。layer默认。只需要以下操作
在初始化或进入的时候加上 setTouchEnabled(true);
实现四个方法中的一个或多个。如:
void MutiTouchTestLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) //返回值是void
{
CCSetIterator iter = pTouches->begin();
for (; iter != pTouches->end(); iter++)
{//这里你要手动处理每一个点!
CCTouch* pTouch = (CCTouch*)(*iter);
CCPoint location = pTouch->locationInView();
}
}
其队三个函数类似!
相关文章推荐
- registerWithTouchDispatcher()函数的使用
- warning C4800: 'VARIANT_BOOL' : forcing value to bool 'true' or 'false' (performance warning)
- warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
- registerWithTouchDispatcher()函数的使用
- registerWithTouchDispatcher 注册触屏事件
- registerWithTouchDispatcher 注册单点触摸事件
- registerWithTouchDispatcher()函数的使用
- [android警告] AndroidManifest.xml警告 Should explicitly set android:allowBackup to true or false
- jquery checkbox反复调用attr('checked', true/false)只有第一次生效
- atlcomcli.h(1756): error C2338: CVarTypeInfo< char > cannot be compiled with /J or _CHAR_UNSIGNED fl
- ATL项目编译注册dll的时候报权限错误:error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.
- fatal error C1047: The object or library file "..."was created with an older compiler than
- column: xxxxxx_ID (should be mapped with insert="false" update="false")
- unable to dequeue a cell with identifier cell - must register a nib or a class for the identifier or
- Python小技巧 – True or False
- 变量与对话框的交互:UpdateData(FALSE)&&UpdateDate(TRUE)
- True/False Positive & True/False Negative (真/假阳性, 真/假阴性)
- Scrapped or attached views may not be recycled. isScrap:false isAttached:true异常
- Project configuration is not up-to-date with pom.xml. Run Maven->Update Project or use Quick Fix
- Repeated column in mapping for entity: .... should be mapped with insert="false" update="false"