CCMenu issue - wrong order of items when they are touched

This issue has already been reported for original cocos2d: http://code.google.com/p/cocos2d-iphone/issues/detail?id=1125

The problem is that method CCMenu::itemForTouch(CCTouch *touch) checks all items in the normal order (as they are drawn on display), however, if there are overlapping items, then the function returns the one which is behind another one, however, logically, the one which is on top should be clicked.

The solution is:

In file CCMenu.cpp in function CCMenu::itemForTouch(CCTouch *touch) replace CCARRAY_FOREACH to CCARRAY_FOREACH_REVERSE.

And in file CCArray.h add CCARRAY_FOREACH_REVERSE:

#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \ if (__array__ && __array__->data->num > 0) \ for(CCObject** arr = __array__->data->arr + __array__->data->num-1, **end = __array__->data->arr; \ arr >= end && ((__object__ = *arr) != NULL/* || true*/); \ arr--)

Hi, Dmitry Matyukhin,
Thanks a lot, the issue was created on http://www.cocos2d-x.org/issues/955.