0

我不知道如何处理瓦片地图图层和其他节点。当整个地图滚动时,我想为菜单按钮、得分、操纵杆等内容制作另一个图层(CCNode),这些图层必须始终保持固定(不滚动)。

self.theMap=[CCTiledMap tiledMapWithFile:@"map.tmx"];
self.bgLayer=[theMap layerNamed:@"bg"];
  [self addChild:theMap z:-1];



  CCNode *joystickNode;
  joystickNode=[CCNode node];
  [bgLayer.parent addChild:joystickNode z:2];


upArrowFrame=[CCSpriteFrame frameWithImageNamed:@"uparrow.png"];
upArrow=[CCButton buttonWithTitle:@"" spriteFrame:upArrowFrame];
[upArrow setTarget:self selector:@selector(upArrowPressed)];
upArrow.position= ccp(190,190);
[joystickNode addChild:upArrow z:2];

现在upArrow在屏幕上根本不可见。如果我添加 toself而不是joystickNode,它将出现。

我什至无法理解,新的 CCNode 应该有什么父级。谁能给我解释一下?我还尝试将新的 CCNode 添加为selfand的子级theMap

编辑:哎呀,它实际上是在移动相机。在这种情况下如何实施?

    -(void)setCenterOfScreen :(CGPoint) position {
    CGSize screenSize=[[CCDirector sharedDirector]viewSize];
    int x=MAX(position.x, screenSize.width/2);
    int y=MAX(position.y, screenSize.height/2);

    x= MIN(x, theMap.mapSize.width * theMap.tileSize.width - screenSize.width/2);
    y= MIN(y, theMap.mapSize.height * theMap.tileSize.height - screenSize.height/2);

    CGPoint goodPoint =ccp(x,y);
    CGPoint centerOfScreen = ccp(screenSize.width/2, screenSize.height/2);
    CGPoint difference = ccpSub(centerOfScreen, goodPoint);

    self.position=difference;


}

- (void)update:(CCTime)dt{


    [self setCenterOfScreen:hero.position];

}
4

0 回答 0