如何在cocos2d环境外实现cocos2d游戏的虚拟摇杆? [英] How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?

查看:195
本文介绍了如何在cocos2d环境外实现cocos2d游戏的虚拟摇杆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款使用cocos2d并需要一个虚拟摇杆的iPad游戏。我有一个原型,并使用SneakyJoystick运行。

I am developing an iPad game that uses cocos2d and requires a virtual joystick. I have a prototype up and running using SneakyJoystick.

然而,我意识到,我的游戏设计要求我使用CCTransitions移动用户之间不同的CCScene实例,以得到我想要的视觉效果。问题是,我不想让用户控件(如操纵杆)受CCTransitions的影响 - 我希望他们保留在屏幕上(在屏幕的不同部分,而不是由CCScene占用的部分。)

However, I realized that my game design requires me to use CCTransitions to move the user between different instances of CCScene in order to get the visual effect I want. The problem is, I don't want the user controls (like the joystick) to be affected by the CCTransitions- I want them to remain on the screen (in a different part of the screen than the part occupied by the CCScene.)

我意识到,这样做的唯一方法是将整个cocos2d环境保存在EAGLView中,该环境占用的区域比整个屏幕小,这允许我保留所有用户

I realized the only way to do this was to keep the entire cocos2d environment in an EAGLView that occupies an area smaller than the entire screen, which allows me to keep all the user controls elsewhere on the screen, where they are unaffected by the scene transitions.

问题是,这意味着SneakyJoystick可能不再是一个选项,因为它是一个CCNode因此可能只会在cocos2d场景图内运行。

The problem is, that means SneakyJoystick is probably no longer an option, as it is a CCNode that therefore will probably only run within the cocos2d scene graph.

我很好奇,如果有人有一个替代解决方案这种情况:一种在cocos2d环境外实现虚拟操纵杆的方法,但是可以以某种方式与cocos2d场景流畅地沟通。

I am curious if anyone has an alternative solution for this situation: A way of implementing a virtual joystick outside the cocos2d environment, but that can somehow communicate fluidly with the cocos2d scene.

如果我能保留SneakyJoystick的功能或非常相似的东西,通过点击cocos2d从这个非cocos2d类的预定更新,或者不知何故否则将用户输入信息从操纵杆类推送到cocos2d。

It would be great if I could retain the functionality of SneakyJoystick or something very similar, by either tapping into the scheduled updates of cocos2d from this non-cocos2d class, or somehow otherwise pushing user input information from the joystick class to cocos2d.

推荐答案

可能你可以创建一个UIView并放在opengl视图。要访问openglView,请使用 [CCDirector sharedDirector] .openGLView 。使用UIView创建操纵杆。因此,它将始终显示,并且不会受CCScene转换影响。

Possibly you can create an UIView and put it over the opengl view. To access the openglView use [CCDirector sharedDirector].openGLView. Create your joystick using UIView. So it will be always shown, and will be not affected by CCScene transitions.

这篇关于如何在cocos2d环境外实现cocos2d游戏的虚拟摇杆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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