Set the Camera Position CCScene

98 Views Asked by At

I've come across an issue with my CCScene. I'm trying to set the position of my scene on the player block. Here is my init for my scene:

  - (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;
}

Here's my init for player block:

    -(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;
}

What currently happens is that it doesn't focus on the player block.

Can anyone clear this up for me?

1

There are 1 best solutions below

0
On

Needed to add this line to my scene:

self.contentSize=CGSizeMake(1000, 1000);

As my sprite lay outside of the scene bounds.