I have three layers in my CCScene. MainLayer which contains GameLayer and HUDLayer. This is what it looks like now:
[ z-Order ] | [ Layer ]
==============================
3 ( Top Most ) | HUDLayer
2 ( Middle ) | GameLayer
1 ( Bottom ) | MainLayer
I have added touch listeners (ccTouchBegan, ccTouchMoved, and ccTouchEnded) on my MainLayer which calls GameLayer‘s method getTouchedObject( CCPoint p_Loc ) which returns the touched object in that layer.
I am now able to successfully ‘touch’ a specific object in the MainLayer. Now, what I want to do is to drag the object touched and put it into the HUDLayer. When I was working with just one layer, I was able to drag and drop different objects with no problem but the need to implement CCLayers came so I divided the main layer into three different layers.
Answers doesn’t need to be cocos2d-x. I understand a bit of Obj-C and can translate Obj-C into C++ so cocos2d answers are welcome. Thanks in advance.
The easiest way to do it, is probably:
CCLayeron the very top calledHoverLayeror something. This is for modularity.HoverLayerat the same position. The user will not “see” anything changed.HUDLayeror not.HoverLayerand add it to the appropriate layer.NOTES:
HUDLayerinstead of theHoverLayer, but your class will be messy.GameLayerwhile dragging, it will end up behind theHUDLayerat some point, so moving the sprite to a top layer is a must.