Scrollable menu using MenuItem's

2019-08-30 22:06发布

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?

1条回答
Animai°情兽
2楼-- · 2019-08-30 22:49

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

detect a swipe, and move the the menuItems

查看更多
登录 后发表回答