Hey,
I'm working with Tile map and Sneaky Joystick, and the map is scrolling by the player's position - he's the center of the view.
But when the map is scrolling, the joystick is moving too.. How to fixation the joystick in a position even after the map scrolled?
The function of the center of the map is that:
-(void)setViewpointCenter:(CGPoint) position {
CGSize winSize = [[CCDirector sharedDirector] winSize];
int x = MAX(position.x, winSize.width / 2);
int y = MAX(position.y, winSize.height / 2);
x = MIN(x, (tilemap.mapSize.width * tilemap.tileSize.width)
- winSize.width / 2);
y = MIN(y, (tilemap.mapSize.height * tilemap.tileSize.height)
- winSize.height/2);
CGPoint actualPosition = ccp(x, y);
CGPoint centerOfView = ccp(winSize.width/2, winSize.height/2);
CGPoint viewPoint = ccpSub(centerOfView, actualPosition);
self.position = viewPoint;
}
And it applies:
-(void)tick:(float)delta {
[self applyJoystick:leftJoystick toNode:player forTimeDelta:delta];
// Set view center
[self setViewpointCenter:player.position];
}
[[CCDirector sharedDirector] setAnimationInterval:1.0f/60.0f];
[self schedule:@selector(tick:) interval:1.0f/120.0f];
SneakyJoystickSkinnedBase *leftJoy = [[[SneakyJoystickSkinnedBase alloc] init] autorelease];
leftJoy.position = leftjoypos;
leftJoy.backgroundSprite = [ColoredCircleSprite circleWithColor:ccc4(255, 0, 0, 128) radius:64];
leftJoy.thumbSprite = [ColoredCircleSprite circleWithColor:ccc4(0, 0, 255, 200) radius:32];
leftJoy.joystick = [[SneakyJoystick alloc] initWithRect:CGRectMake(0,0,128,128)];
leftJoystick = [leftJoy.joystick retain];
[self addChild:leftJoy];
I tried to make the joystick as a menu item, but I don't know how to. So what to do?