Revision: 31132
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 30, 2010 18:18 by cell-gfx
Initial Code
-(void)setPlayerPosition:(CGPoint)position {
CGPoint tileCoord = [self tileCoordForPosition:position];
int tileGid = [_meta tileGIDAt:tileCoord];
if (tileGid) {
NSDictionary *properties = [_tileMap propertiesForGID:tileGid];
if (properties) {
NSString *collision = [properties valueForKey:@"Collidable"];
if (collision && [collision compare:@"True"] == NSOrderedSame) {
return;
}
NSString *collectable = [properties valueForKey:@"Collectable"];
if (collectable && [collectable compare:@"True"] == NSOrderedSame) {
[_meta removeTileAt:tileCoord];
[_foreground removeTileAt:tileCoord];
self.numCollected++;
[_hud numCollectedChanged:_numCollected];
}
}
}
ccTime moveDuration = 0.3;
id playerMove = [CCMoveTo actionWithDuration:moveDuration position:position];
id cameraMove = [CCFollow actionWithTarget:_player worldBoundary:CGRectMake(0, 0, (_tileMap.mapSize.width * _tileMap.tileSize.width), (_tileMap.mapSize.height * _tileMap.mapSize.height))];
[_player runAction:playerMove];
[self runAction:cameraMove];
}
Initial URL
Initial Description
Use this variation of **setPlayerPosition** in your HelloWorldScene.m file to negate the need to use **setViewpointCenter** to manually calculate the viewport to track your player. This uses the **CCFollow** function as demonstrated in ActionsTest, one of the test apps included with cocos2D. Also to note is that the player movement is controlled by **CCMoveTo** which gives the player the same smooth movement around the map that the enemies have.
Initial Title
Setting cocos2D camera position using CCFollow
Initial Tags
ios
Initial Language
Objective C