/ Published in: Objective C
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.
Expand |
Embed | Plain Text
-(void)setPlayerPosition:(CGPoint)position { CGPoint tileCoord = [self tileCoordForPosition:position]; int tileGid = [_meta tileGIDAt:tileCoord]; if (tileGid) { if (properties) { if (collision && [collision compare:@"True"] == NSOrderedSame) { return; } 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]; }
Comments
Subscribe to comments
You need to login to post a comment.

[collision compare:@"True"] == NSOrderedSameshould be written as[collision isEqualToString:@"True"]Wow, I needed this and it's for that exact project that you gave the code. Thanks a ton!
By the way, for iPhone 5 I have to change CCFIXARTIFACTSBYSTRECHING_TEXEL from 0 to 1 in the ccConfig.h file due to the border of some tiles appearing while moving.