Cocos2d、CCMenuSprite、缩放和定位问题
我不知道如何在场景中正确定位一些使用缩放精灵创建的菜单按钮。
如果我创建精灵,缩放它们并设置它们的位置,一切都会顺利。
如果我创建精灵,缩放它们,设置它们的位置,然后使用它们创建 CCMenuItemSprite,它们都会向左和向下移动。
如果我创建精灵,使用它们创建 CCMenuItemSprite,缩放菜单项并设置菜单项位置,它们都会向右和向上移动。
当然,所有这些设置都是使用相同的比例因子和中心点坐标完成的。
我缺少什么?
谢谢!
编辑:解决了!
我明白了!!这完全取决于菜单的坐标系如何工作以及缩放菜单时它如何反应。
我现在不知道我是否对问题采取了不正确的方法(这很有可能),或者整个系统的思考方式是否存在一些棘手的问题。
我会深入研究它并尽快写一个小教程。
再次感谢:D
I can't figure out how to correctly position in the scene some menu buttons created with scaled sprites.
If I create the sprites, scale them, and set their position, it all goes fine.
If I create the sprites, scale them, set their position and then use them to create the CCMenuItemSprite they are all shifted left and down.
If I crete the sprites, use them to create the CCMenuItemSprite, scale the menu item and set the menu items position, they are all shifted right and up.
All those settings are done with the same scale factor and center point coordinates of course.
What am I missing??
Thanks!
EDIT: SOLVED!!
I got it figured out!! It was all due to how the coordinate system of the menu works and how it reacts when the menu is scaled.
I don't know right now it I was taking a non correct approach to the problem, which is very possible, or if there is something tricky in how all the system is thought.
I will dig into it an write a little tutorial ASAP.
Thanks again :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这是一个非常古老的问题,但我只是想在这里分享发生在我身上的事情(我希望它有帮助)。我刚刚遇到了这个问题中描述的相同问题,正如@mokagio 上面所说,问题在于菜单的坐标系统如何工作。
首先,我用它创建了一个 Sprite 和一个 MenuItemSprite,但我永远无法正确定位它们。然后我意识到我应该基于 MenuItemSprite 而不是在 Sprite 中进行所有缩放和定位,并且一切正常!
我使用的代码是:
另外,请注意,根据菜单坐标系而不是世界坐标系设置按钮位置很重要。
I know this is a very old question, but I just wanted to share what happened to me here (I hope it is helpful). I just had the same problem described in this question and as @mokagio said above the problem is with how the coodinate system of the menu works.
First I created a Sprite and a MenuItemSprite with it, but I could never position them correctly. Then I realised that I should do all the scaling and positioning based on the MenuItemSprite and not in the Sprite and everything worked fine!
The code I used was:
Also, please note that it is important to set the button position according to the menu coordinate system and not to the world coordinate system.