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
?
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:
- (void)moveHero; {
[self applyJoystick:leftJoystick toNode:hero forTimeDelta:1.0/60.0f]];
}
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 other HUD
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!