I have been following the guide on
http://johnehartzog.com/2009/10/2d-scrolling-game-with-cocos2d-tilemap-with-zoom/
I'm calling this code in a schedule using the main character's (hero) position as the point that is passed to setViewpointCenter.
My tilemap's position of (0,-320) as this will then get it load on the top left hand corner of the tilemap instead of the bottom left which setting its position to (0,0) will do. The tilemap and the hero are part of the gamelayer.
The problems i'm facing are that from the example below I'm assuming that the center point is that of the tilemap and not the iphone screen, however it then means it shows the top left hand side of the tilemap but the scrolling doesn't work
Can anyone she some light on how to achieve scrolling as the hero moves (which uses your touchlocation)
- (void)setViewpointCenter:(CGPoint)point {
CGPoint centerPoint = ccp(240, 160);
viewPoint = ccpSub(centerPoint, point);
// dont scroll so far so we see anywhere outside the visible map which would show up as black bars
if(point.x < centerPoint.x)
viewPoint.x = 0;
if(point.y < centerPoint.y)
viewPoint.y = 0;
gameLayer.position = viewPoint;
}
[img]http://img294.imageshack.us/img294/4817/photo2q.jpg[/img]