I am developing an iPad game that uses cocos2d and requires a virtual joystick. I have a prototype up and running using SneakyJoystick.
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.)
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.
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.
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.
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.
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.
来源:https://stackoverflow.com/questions/6166430/how-can-i-implement-a-virtual-joystick-for-a-cocos2d-game-outside-the-cocos2d-en