触及cocos2d / cocos2d-x中的优先级

时间:2012-09-19 03:32:56

标签: cocos2d-iphone cocos2d-x

我正在努力尝试中的触摸。我对触摸的优先级有疑问,例如,当我使用CCMenuItemSpriteCCControlButton添加到具有setTouchEnabled(true)

的图层时

甚至如果我放了一个 我发现触摸不首先提供给ccTouchesBegan(...我的意思是图层),而是由CCMenuItemSpriteCCCOntrolButton回拨。

此外,如果我在所有图层上添加额外的图层顶部并setTouchEnable(True),我会得到相同的结果 触摸首先给予menuitem和控制按钮,触摸后吞下触摸。

我们有什么方法可以改变触摸的优先级?要么 有什么方法可以覆盖CCControlButtonCCMEnuItemSprite ... ccTouchesBegan或者移动 毕竟我想要CCMenuItemCControlButton的触摸位置 否则我必须重新考虑CCSprite

3 个答案:

答案 0 :(得分:2)

覆盖您的CCLayer方法

YOUR_LAYER::registerWithTouchDispatcher{
    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, INT_MIN, true);
}

答案 1 :(得分:2)

您可以在CCMenu.h中找到它

enum {
    //* priority used by the menu for the event handler
    kCCMenuHandlerPriority = -128,
};

因此菜单的默认优先级设置为-128,如果要在CCMenu之前使某些图层检测到触摸,请尝试将其优先级设置为小于-128

答案 2 :(得分:0)

哪个首先检测触摸只取决于Widget的优先级,我想你为什么感到困惑的是你可能认为它依赖于Widget的Zorder.So,你可以改变你的层的优先级添加,并确保优先级低于菜单项的优先级,即Cococs2d-x中的-128。

CCLayer.h

/** priority of the touch events. Default is 0 */
virtual void setTouchPriority(int priority);    

CCMenu.h

enum {
    //* priority used by the menu for the event handler
    kCCMenuHandlerPriority = -128,
};
相关问题