
Platformer Progress Update 2
Another little update on the progress of the platformer. Its now up to build 0.75 and I’ve been doing lots of fiddling with little things here and there, because I have been busy.
Heres the main points of interest since the last update:
I’ve added a ram counter to the showFPS debug text. It reads high on the simulator because it counts more than it should.
The level select screen has a scrolling interface which takes 4 level buttons on each page. Each Page will represent a ‘Stage’ and I like to think that each stage will be of a different theme.
Credits menu has the same level scroller implemented, but will have a page for programming, art & music peoples, along with links for the respective people, and text (maybe a little quote).
Settings menu now has particle toggle and player motion streak toggles added, but don’t change anything yet.
Fundamentals of a splash-screen, which will come up automatically, play a little animation, then be dismissed to the main menu.
Experiments with the CCCamera classes (the cocos2d camera)
I’ve ran through 4 different techniques for camera control in cocos2d. Because I found little help on this on the net, I shall post some little snippets to guide anyone who needs them. I have my player referenced as player in these samples. This is mostly old code, I have cleaned it up and simplified… This all belongs in a tick/gameloop function to actually update the position
Option 1:
Scroll the layer on a lock onto the player. The PTM_RATIO and +90 account for position on screen, and box2d.
CGPoint cameraPosition = ccp(-1 * playerPosition.x * PTM_RATIO + 90, -1 * playerPosition.y *PTM_RATIO + 90); [self setPosition:cameraPosition];
Option 2:
Use CCFollow to do essentially the same things as Option 1. This will not show anything outside the worldBoundary area. Because Im using Tile tilemaps, I have added two points to the tilemap to define the max/min camera areas.
CCTMXObjectGroup *cameraobjects = [tileMap objectGroupNamed:@"Objects"]; NSMutableDictionary *spointPoint = [cameraobjects objectNamed:@"start"]; int spointx = [[spointPoint valueForKey:@"x"] intValue]; int spointy = [[spointPoint valueForKey:@"y"] intValue]; NSMutableDictionary *epointPoint = [cameraobjects objectNamed:@"end"]; int epointx = [[epointPoint valueForKey:@"x"] intValue]; int epointy = [[epointPoint valueForKey:@"y"] intValue]; CGRect tilemapBounds = CGRectMake(0, 0, epointx - spointx, epointy - spointy); id cameraMove = [CCFollow actionWithTarget:player worldBoundary:tilemapBounds]; [self runAction:cameraMove];
Option 3:
Use the CCCamera. I found a lot of websites recommend against using CCCamera, because it doesn’t scroll the layer, and can make co-ordinates a pain later with conversions. I actually needed it to work, but camera control isn’t high on my list right now. The values are all 0, because I haven’t tried it out properly yet.
[self.camera setCenterX:0 centerY:0 centerZ:0];<br /> [self.camera setEyeX:0 eyeY:0 eyeZ:0]; //[CCCamera getZEye] is often used in eyeZ here
Option 4:
Very similar to Option2, but a little different in form. It uses a function to get the position of the object we want to track, and the function takes into account the boundaries.
-(void)setViewpointCenter:(CGPoint) position { CGSize winSize = [[CCDirector sharedDirector] winSize]; //I store these values in a singleton when the map is loaded int mapWidth = someNumber; int mapHeight = someOtherNumber; int x = MAX(position.x, winSize.width / 2); int y = MAX(position.y, winSize.height / 2); x = MIN(x, (mapWidth * mapWidth) - winSize.width / 2); y = MIN(y, (mapHeight * mapHeight) - winSize.height/2); CGPoint actualPosition = ccp(x, y); //figure out where the 'camera' will centre, and where the viewpoint is based on above calculations CGPoint centerOfView = ccp(winSize.width/2, winSize.height/2); CGPoint viewPoint = ccpSub(centerOfView, actualPosition); self.position = viewPoint;
which is used with
[self setViewpointCenter:player.position];
In the gameloop function
I really need to figure out the syntax highlighting plugin to make that read nicer… Hopefully more to come when I’m done with my final exams in two weeks.