设置摄像机位置CCScene

时间:2014-03-19 01:31:52

标签: objective-c cocos2d-iphone ccscene

我遇到过CCScene的问题。我正试图在播放器块上设置场景的位置。这是我的场景的初始化:

  - (id)init
{

    // Apple recommend assigning self with supers return value
    self = [super init];
    if (!self) return(nil);

    self.userInteractionEnabled = YES;    

    // Create a colored background (Dark Grey)
    CCNodeColor *background = [CCNodeColor nodeWithColor:[CCColor colorWithRed:0 green:0 blue:0 alpha:1.0f]];
    [self addChild:background];

    // Add a sprite
    _player = [[PlayerBlock alloc]initWithX:[bp getPlayerX] withY:[bp getPlayerY] maxX:1000 maxY:1000 levelBlocks:blocks endBlock:fb];

    [self addChild:_player];

    self.positionType=CCPositionTypePoints;
    self.position=_player.position;
    // done
    return self;
}

这是我的玩家块初始化:

    -(id)initWithX:(double)x withY:(double)y maxX:(double)maxX maxY:(double)maxY levelBlocks:(NSMutableArray*)sprites endBlock:(FinishBlock*)finishBlock{
    self=[self initWithImageNamed:@"player.png"];
    self.position  = ccp(x,y);
    _finish=finishBlock;
    _sprites=sprites;
    _startX=x;
    _startY=y;
    _maxX=maxX;
    _moving=0;
    _maxY=maxY;
    self.width=25;
    self.height=25;
    self.positionType=CCPositionTypePoints;
    return self;
}

目前发生的事情是它没有关注玩家块。

任何人都可以为我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

需要将此行添加到我的场景中:

self.contentSize=CGSizeMake(1000, 1000);

因为我的精灵位于场景范围之外。