Tutorial :Scrollable menu using MenuItem's


What I am trying to accomplish with Cocos2d, is to create a horizontal menu, which can be swiped from left to right. I posted an image, to show my idea.

The image below has a white bar, where I want to show MenuItem objects, now I want to be able to do a swipe in the white region, so that the next menu item is centered.

Example http://www.wimhaanstra.com/images/MenuExample.png

The problem I am facing is, I would really like to use the Menu (& MenuItem) functionality of Cocos2d, but it seems somehow that the MenuItem object does not accept touches other than just tapping it. Also I want the swipe to be detected not only on the MenuItem, but the whole white bar.

What would be the best approach for this?

  • Somehow incorporate an UIScrollView, but that would be a shame, because I would like to use OpenGL for everything
  • Subclasss the MenuItem class, to create one where the ccTouchBegan is handled, and somehow move the whole Menu?
  • Just leave the whole Menu idea behind, and replace the Menu and MenuItems with sprites which support touching.

I read somewhere that MenuItem's shouldn't really be used for this kind of work, but why not?


Layer can handle touches event. you can put you menuItems into one layer.

detect a swipe, and move the the menuItems

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »