• 在cocos2d中使tilemap地图有无限循环的效果


    首先我们要根据所需的地图制作两张tilemap地图,然后根据当前的position判断是目前是哪一张地图进行合理的显示。

    附主要代码:

     1 -(void) setViewPointCenter:(CGPoint)position
     2 {     
     3     CGSize winSize = [[CCDirector sharedDirector] winSize];
     5     if (-1*self.position.x>((_tilemap.mapSize.width * _tilemap.tileSize.width)+_tilemap.position.x-winSize.width-1.0)) {
     6         if ((-1*self.position.x>(_tilemap1.mapSize.width * _tilemap1.tileSize.width)+_tilemap1.position.x-winSize.width-1.0))
     7         {
     8             _tilemap.position = ccp(_tilemap1.position.x+(_tilemap1.mapSize.width * _tilemap1.tileSize.width),0);
     9         }
    10         else {
    11             CGPoint mapPosition = [self tilePosFromLocation:_spiderman.position tileMap:_tilemap1];
    12             int x = MAX(position.x, winSize.width / 2);
    13             int y = MAX(position.y, winSize.height / 2);
    14             x = MIN(x, (_tilemap1.mapSize.width * _tilemap1.tileSize.width)+_tilemap1.position.x
    15                     - winSize.width / 2);
    16             y = MIN(y, (_tilemap1.mapSize.height * _tilemap1.tileSize.height)
    17                     - winSize.height/2);
    18             CGPoint actualPosition = ccp(x, y);
    19             
    20             CGPoint centerOfView = ccp(winSize.width/2, winSize.height/2);
    21             CGPoint viewPoint = ccpSub(centerOfView, actualPosition);
    22             self.position = viewPoint;
    23         }
    24     }
    25     else {
    26         CGPoint mapPosition = [self tilePosFromLocation:_spiderman.position tileMap:_tilemap];
    27         int x = MAX(position.x, winSize.width / 2);
    28         int y = MAX(position.y, winSize.height / 2);
    29         x = MIN(x, (_tilemap.mapSize.width * _tilemap.tileSize.width)+_tilemap.position.x
    30                 - winSize.width / 2);
    31         y = MIN(y, (_tilemap.mapSize.height * _tilemap.tileSize.height)
    32                 - winSize.height/2);
    33         CGPoint actualPosition = ccp(x, y);
    35         CGPoint centerOfView = ccp(winSize.width/2, winSize.height/2);
    36         CGPoint viewPoint = ccpSub(centerOfView, actualPosition);
    37         self.position = viewPoint;
    38         if((-1*self.position.x>(_tilemap.mapSize.width * _tilemap.tileSize.width)+_tilemap.position.x-winSize.width-1.0))
    39         {
    40             _tilemap1.position = ccp(_tilemap.position.x+(_tilemap.mapSize.width * _tilemap.tileSize.width),0);
    41         }
    42     }
    43 }

    整个思想还是比较简单,就是根据目前的地图将第二章地图放到目前地图的后面紧跟,注意tilemap大小的计算:

    _tilemap1.mapSize.width * _tilemap1.tileSize.width
  • 相关阅读:
    《算法竞赛入门经典》《算法竞赛入门经典——训练之南》:勘误、讨论及代码
    codeforces 340B Maximal Area Quadrilateral(叉积)
    codeforces 340C Tourist Problem(简单数学题)
    codeforces 340A The Wall(简单数学题)
    UVALive 4043 Ants(二分图完美匹配)
    UVA 11865 Stream My Contest(最小树形图)
    UVA 11354 Bond(最小瓶颈路+倍增)
    UVALive 5713 Qin Shi Huang's National Road System(次小生成树)
    UVALive 3661 Animal Run(最短路解最小割)
    卡尔曼滤波器
  • 原文地址:https://www.cnblogs.com/dinghing154/p/2623165.html
Copyright © 2020-2023  润新知