About CCMenu::setHandlerPriority(int newPriority)


#1

我还是说中文吧,英文仅为看懂水平。。。。
这个函数之前的assert问题被修正,可是现在无论是ccmenu还是继承自它的子类,都不能正确再次设置priority。。。。求指教。。。我看了一下放taget的数组,里边n个指针指向的都是同一个内存地址。。。小弟才疏学浅,忘各位老大指教。

ps. wenbin wang has feedback to me…thank you for your help!!!As follows…

pDispatcher~~>findHandler return NULL is because CCMenu::registerWithTouchDispatcher hasn’t be called yet.
CCMenu::registerWithTouchDispatcher is called by the onEnter function, after that, the TouchDispatcher will add a handler to the CCMenu, and pDispatcher~~>findHandler(this) will return the handler instead of NULL. See the implement above.

So In CCMenu::setHandlerPriority(int newPriority), firstly I check if the handler has been add by pDispatcher~~>findHandler. If it is, call pDispatcher~~>setPriority(newPriority, this); to modify the touchPriority. Otherwise, just store the priority in member m_handlerPriority and wait CCMenu::registerWithTouchDispatcher() to handle it.


#2

Just another vote for this.

I think most of the devs will do the initial jobs on init(); function (or even in constructor) including the touch priorities of the menus.
This kind of re-ordering touch priorities are crucial for making Popups or Dialogs which can be ‘stacked’ over themselves.

I really don’t like modifying the original code INSIDE the LIBRARY itself, but I had to modify it.

I hope in the next version this changes committed to the main repository.

Thanks


#3

Yes, I also think that setHandlerPriority should store given priority in a member veriable to use it in registerWithTouchDispatcher if handler is not currently registered. In current cocos2d-x version I can’t see any proper place to put setHandlerPriority because it crashes even if you put it into your Layer::onEnter() (as I said here: http://www.cocos2d-x.org/boards/6/topics/12661).