Not really sure why I am getting this error but I have looked in the .h file and I can’t seem to come up with the reason xCode is throwing this error:
// on "init" you need to initialize your instance
-(id) init
{
if ((self=[super init])) {
_batchNode = [CCSpriteBatchNode batchNodeWithFile:@"Sprites.pvr.ccz"]; //1
[self addChild:_batchNode]; //2
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Sprites.plist"]; //3
_ship = [CCSprite spriteWithSpriteFrameName:@"SpaceFlier_sm_1.png"]; //4
CGSize winSize = [CCDirector sharedDirector].winSize; //5
_ship.position = ccp(winSize.width * 0.1, winSize.height * 0.5); //6
[_batchNode addChild:_ship z:1]; //7
}
return self;
// 1) Create the CCParallaxNode
_backgroundNode = [CCParallaxNode node];
[self addChild:_backgroundNode z:-1];
// 2) Create the sprites we'll add to the CCParallaxNode
_spacedust1 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"];
_spacedust2 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"];
_planetsunrise = [CCSprite spriteWithFile:@"bg_planetsunrise.png"];
_galaxy = [CCSprite spriteWithFile:@"bg_galaxy.png"];
_spacialanomaly = [CCSprite spriteWithFile:@"bg_spacialanomaly.png"];
_spacialanomaly2 = [CCSprite spriteWithFile:@"bg_spacialanomaly2.png"];
// 3) Determine relative movement speeds for space dust and background
CGPoint dustSpeed = ccp(0.1, 0.1);
CGPoint bgSpeed = ccp(0.05, 0.05);
// 4) Add children to CCParallaxNode
[_backgroundNode addChild:_spacedust1 z:0 parallaxRatio:dustSpeed positionOffset:ccp(0,winSize.height/2)];
[_backgroundNode addChild:_spacedust2 z:0 parallaxRatio:dustSpeed positionOffset:ccp(_spacedust1.contentSize.width,winSize.height/2)];
[_backgroundNode addChild:_galaxy z:-1 parallaxRatio:bgSpeed positionOffset:ccp(0,winSize.height * 0.7)];
[_backgroundNode addChild:_planetsunrise z:-1 parallaxRatio:bgSpeed positionOffset:ccp(600,winSize.height * 0)];
[_backgroundNode addChild:_spacialanomaly z:-1 parallaxRatio:bgSpeed positionOffset:ccp(900,winSize.height * 0.3)];
[_backgroundNode addChild:_spacialanomaly2 z:-1 parallaxRatio:bgSpeed positionOffset:ccp(1500,winSize.height * 0.9)];
}
First off, unless C2D somehow magically changes the way
returnworks, you proceed to do a lot of stuff afterreturning which can never be reached. You’ve justreturned; you’ve exited the method. It’s like telling the painter to leave the room he’s working on and go home for the day… then screaming out to nothingness that he should paint the walls red. Actually, you wouldn’t get to scream at all. Here’s an example:xwould be assigned ten and then you would return. Any lines afterwards are meaningless. Second of all, there’s this line here.It occurs within an
ifstatement. The variablewinSizecan only be used within the constraints of theifstatement you declared it in. It’s “out of scope” of anything else. For example, the following will give the same warning.Why not place all the stuff below
returninside theifloop, right before it closes?