使用MenuItem的可滚动菜单 [英] Scrollable menu using MenuItem's

查看:212
本文介绍了使用MenuItem的可滚动菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Cocos2d实现的是创建一个水平菜单,它可以从左到右滑动。我发布了一个图片,以显示我的想法。

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.

下面的图片有一个白色的条,我想显示MenuItem对象,现在我想能够做在白色区域滑动,以便下一个菜单项居中。

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.

我面临的问题是,我真的想使用Cocos2d的Menu(& MenuItem)功能, MenuItem对象不接受触摸而不仅仅是点击它。此外,我希望不仅可以在MenuItem上检测到滑动,而且还可以检测整个白色条。

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?


  • 某种程度上包含了一个UIScrollView,但这将是一个耻辱,因为我想使用OpenGL的一切

  • 子类MenuItem类,创建一个处理ccTouchBegan的地方,并以某种方式移动整个菜单?

  • 只需将整个菜单理念放在后面,用支持触摸的sprite替换Menu和MenuItems。

我在某处读到了MenuItem不应该用于这种工作,但为什么不呢?

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

推荐答案

图层可以处理触摸事件。
您可以将menuItems放入一个图层。

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

检测滑动,并移动menuItems

detect a swipe, and move the the menuItems

这篇关于使用MenuItem的可滚动菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆