Detection of CCSprite when overlapped

Detection of CCSprite when overlapped
0.0 0


Hi all, I had met this problem with the selection of CCSprite when 2 or more CCSprite are overlapped. It seems like it always detect the first object in the children container that it loops to when the CCSprite is being touched. I had read up about the sorting of the children container, but it seems like the sorting is not being carried out after i change the ZOrder of the CCSprite. I change the ZOrder of the CCSprite the moment i detect that it is being selected. Can anyone enlightened me on when the sort function will be called?


Perhaps you need to perform a manual loop taking into account the z-order of the sprites.
You can keep a sorted list of the sprites and select the first one which results touched.



The CCNode will call the sortAllChildren method in the visit method each frame.


but i believe somewhere is also doing it. is it that i have to override some functions in order for me to sort it myself? sortAllChildren Method is already sorting it by zorder, however it doesnt seem like it is sorted whenever i click on the overlapped sprite.

`Xia Xiao
thanks. it always called whenever the draw call is executed. but i couldnt get it to work properly. what i did was, i change the zorder of the sprite when i touch it. it suppose to sort after i remove my finger, but it didnt and when i touch the 2 overlapped sprite, it detects the one below. I am trying to print out the objects inside the children container. i kept having error on that though.