Sneaky 输入操纵杆的 HUD 层 (cocos2d iPhone)
我使用 SneakyInput 操纵杆移动我的精灵,并为我的游戏使用 TMX 地图。我在我的应用程序中添加了自动相机移动,因此英雄精灵始终可见。当我浏览地图时,操纵杆离开屏幕(它停留在原来的位置)。我制作了一个HUD,使操纵杆始终处于同一位置,并且不会随着地图移动。操纵杆在屏幕上显示得很好,但是当我拖动它时,它不会移动我的英雄。
我已将 HUDLayer 设为 GameLayer 中的 CCLayer,这是我制作 moveHero
方法的地方。操纵杆可以工作,但是当我在地图上移动它时,自动摄像机移动可以工作,但是操纵杆保持在相同的位置,并且很快就看不见了。我知道问题是我做 [self setCenter....blah blah blah];
而不是仅将 Level1
设置为中心。如何仅移动 Level1
的相机,而不移动 HUDLayer
?
I'm using the SneakyInput Joystick to move my sprite, and TMX maps for my game. I added auto-camera-movement to my app, so the hero sprite is always visible. When I go through my map, the joystick goes off the screen (it stays where it's original position is). I made a HUD so that the joystick is always at the same position, and doesn't move along with the map. The joystick shows up on screen fine, but when I drag it it doesn't move my hero.
I've made HUDLayer a CCLayer in GameLayer, which is where I'm making the moveHero
method. The joystick works, but when I move it across the map, the auto-camera-movement works, but the joysticks stay in there same position, and are out of view pretty soon. I know the problem is that I do [self setCenter....blah blah blah];
instead of only setting Level1
as the center. How do I only move the camera for Level1
, and not HUDLayer
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里是我找到的有关如何使用的链接这堂课。这看起来相当简单。我认为您想将方法
- (void)moveHero
更改为:因为在初始化
HUD
时,您似乎已经保留了对左操纵杆的引用。好的,如果您想基于这 2 个点(操纵杆和其他项目)将
HUD
图层居中,您只需将它们放置在 2D 网格中,然后从那里找出中心点。我假设您正在使用横向模式的 iPhone 屏幕。那么尺寸是480x320。该屏幕的中心是 (240, 160),因此,我会将这个中心用于我的操纵杆和其他HUD
项目。因此,我可能会将操纵杆设置为 (10, 10),将其他项目(假设该项目的尺寸为 (x, y))设置为 ((470 - x), 10),这将使这些项目都具有它们周围有 10 像素边框。希望有帮助!
Here is a link I found on how to use this class. It seems fairly straight forward. I think you want to change the method
- (void)moveHero
to:as it seems you already kept a reference to the left Joystick when you initialized the
HUD
.Ok, if you want to centre the
HUD
layer based on those 2 points (the joystick and the other item), you need only lay them out in a 2D grid, and figure out the centre point from there. I'll assume you are working with an iPhone screen in landscape mode. Then the dimensions are 480x320. The centre of this screen is (240, 160), and so, I would use this centre for my joystick and otherHUD
item. So I would probably set my joystick at (10, 10), and my other item (assume dimensions of this item to be (x, y)) at ((470 - x), 10), which would give the items both a 10 pixel boarder around them.Hope that Helps!