달력

10

« 2024/10 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
http://snipplr.com/view/39706/setting-cocos2d-camera-position-using-ccfollow/

  1. -(void)setPlayerPosition:(CGPoint)position {
  2. CGPoint tileCoord = [self tileCoordForPosition:position];
  3. int tileGid = [_meta tileGIDAt:tileCoord];
  4. if (tileGid) {
  5. NSDictionary *properties = [_tileMap propertiesForGID:tileGid];
  6. if (properties) {
  7. NSString *collision = [properties valueForKey:@"Collidable"];
  8. if (collision && [collision compare:@"True"] == NSOrderedSame) {
  9. return;
  10. }
  11. NSString *collectable = [properties valueForKey:@"Collectable"];
  12. if (collectable && [collectable compare:@"True"] == NSOrderedSame) {
  13. [_meta removeTileAt:tileCoord];
  14. [_foreground removeTileAt:tileCoord];
  15. self.numCollected++;
  16. [_hud numCollectedChanged:_numCollected];
  17. }
  18. }
  19. }
  20.  
  21. ccTime moveDuration = 0.3;
  22. id playerMove = [CCMoveTo actionWithDuration:moveDuration position:position];
  23. id cameraMove = [CCFollow actionWithTarget:_player worldBoundary:CGRectMake(0, 0, (_tileMap.mapSize.width * _tileMap.tileSize.width), (_tileMap.mapSize.height * _tileMap.mapSize.height))];
  24. [_player runAction:playerMove];
  25.  
  26. [self runAction:cameraMove];
  27.  
  28. }

:
Posted by netkorea