Iphone 调度程序优先级问题?

Iphone 调度程序优先级问题?,iphone,ios,cocos2d-iphone,Iphone,Ios,Cocos2d Iphone,使用我在主目录中初始化的CCTouchDispatcher [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; 我认为到目前为止这是正确的-我有拖放工作和我的触摸的一切,但当我把一个精灵拖到一个CCMenu的顶部时,触摸优先权在菜单上,而不再在精灵上-有没有办法解决这个问题 gameBoard = [CCMenu menuWithItems:nil];

使用我在主目录中初始化的CCTouchDispatcher

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
我认为到目前为止这是正确的-我有拖放工作和我的触摸的一切,但当我把一个精灵拖到一个CCMenu的顶部时,触摸优先权在菜单上,而不再在精灵上-有没有办法解决这个问题

gameBoard = [CCMenu menuWithItems:nil];
    [self addChild:gameBoard z:-1];
(我稍后填充游戏板)

我没有使用CCTouchDispatcher和手势识别器,但无论出于什么原因,它都不会触发ccTouchEnded,所以我想我会试试看


感谢您的帮助

找到了解决方法

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
只需将0更改为-129或更低。CCMenu的优先级为-128,该值越低,优先级越高

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-130 swallowsTouches:YES];

因此,这允许将精灵堆叠到一系列按钮上,精灵仍能识别触摸。

这是一个聪明的解决方案。但我认为更好的解决方案是您自己实现CCMenu。据我所知,许多人在按钮上使用CCMenu或你可以按下的东西。但它有许多你无法克服的局限性。例如,CCMenu上不能有多个回调函数。所以我建议您有自己的类来实现它

这里有一些C++代码,希望能有所帮助(但是你仍然需要实现所有的方法,LOL):

class ownButton : public CCNode
{
  public:
  ownButton();

  void init(const char* normalPicPath, const char* pressedPicPath, const char* disabledPicPath, const char* basePicPath);
  bool isContainpoint(CCTouch *touch); 
  void pressed();
  void disabled();
  void normalized();
  int getStatus();
  virtual CCSize getSize();
protected:
  CCSprite* normalPicSprite_;
  CCSprite* pressedPicSprite_;
  CCSprite* disabledPicSprite_;
  CCSprite* basePicSprite_;
  int stat_;
};