Reputation: 1280
My game app that was working perfectly fine on IOS 8 (built with Xcode 6) is all of sudden experiencing many issues when built using Xcode 7 with IOS 9. Here is how the game used to look. (How it should look). Here is it running on IOS 9 (broken)
GAME SCENE CODE
Code for creating the Game Board in Game Scene
-(void) createBoard {
self.buttons=[NSMutableArray new];
if (self.boardBlur != nil ) {
[self.boardBlur removeAllChildren];
}
self.backgroundColor=[UIColor clearColor];
// Use for Christmas Easter egg
/* NSString *snowPath = [[NSBundle mainBundle] pathForResource:@"SnowParticle" ofType:@"sks"];
SKEmitterNode *snow = [NSKeyedUnarchiver unarchiveObjectWithFile:snowPath];
snow.particlePositionRange=CGVectorMake(self.frame.size.width, 20);
snow.position=CGPointMake(self.frame.size.width/2,self.frame.size.height);
snow.zPosition=-3;
[self addChild:snow];*/
if (self.boardFrame != nil) {
[self.boardFrame removeFromParent];
[self.boundingBox removeFromParent];
}
self.boardFrame = [SKSpriteNode spriteNodeWithImageNamed:@"gameBoard2"];
self.boardFrame.color= self.level.baseColor;
self.boardFrame.colorBlendFactor=1.0;
self.boardFrame.alpha = .7;
self.boardFrame.zPosition=-1;
// self.boardFrame.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)+40);
self.boardFrame.size=self.size;
if (self.boardBlur == nil) {
self.boardBlur=[[SKEffectNode alloc]init];
self.boardBlur.filter=[CIFilter filterWithName:@"CIGaussianBlur"];
[self.boardBlur.filter setDefaults];
[self.boardBlur.filter setValue:@5.0 forKey:kCIInputRadiusKey];
self.boardBlur.shouldEnableEffects=NO;
self.boardBlur.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)+40);
[self addChild:self.boardBlur];
}
[self.boardBlur addChild:self.boardFrame];
[self displayMessage:self.level.name color:[UIColor whiteColor]];
[self createHUD];
CGRect playSurface=CGRectInset(self.frame, 36,36);
self.gridSize=fmin(playSurface.size.width,playSurface.size.height)/(fmax(self.level.width,self.level.height));
if (self.gridSize > 60) {
self.gridSize=60;
}
CGRect oldPlaySurface =playSurface;
playSurface=CGRectMake(0,0,self.gridSize*self.level.width,self.gridSize*self.level.height);
self.boardFrame.size=CGRectInset(playSurface, -24, -24).size;
self.boardBlur.zPosition=-2;
self.boundingBox=[SKShapeNode shapeNodeWithRect:CGRectInset(self.boardFrame.frame,self.gridSize/1.7,self.gridSize/1.7) cornerRadius:7.0];
self.boundingBox.strokeColor=[SKColor clearColor];
self.boundingBox.position=self.boardBlur.position;
self.boundingBox.zPosition=-5;
[self addChild:self.boundingBox];
self.ballSize=self.gridSize-6;
self.enlargeAction=[SKAction resizeToWidth:self.ballSize+5 height:self.ballSize+5 duration:0.2];
self.shrinkAction=[SKAction resizeToWidth:self.ballSize height:self.ballSize duration:0.2];
self.enlargeInAction=[SKAction resizeToWidth:self.ballSize height:self.ballSize duration:0.3];
self.shrinkOutAction=[SKAction resizeToWidth:0 height:0 duration:0.3];
CGFloat horizontalSpace = (playSurface.size.width-self.gridSize*self.level.width);
CGFloat verticalSpace = (playSurface.size.height-self.gridSize*self.level.height);
self.topOffset=80+verticalSpace/2+(oldPlaySurface.size.height-playSurface.size.height)/2;
self.leftOffset=40+horizontalSpace/2+(oldPlaySurface.size.width-playSurface.size.width)/2;
for (int y=0; y < self.level.height; y++) {
for (int x = 0; x < self.level.width; x++) {
//SKSpriteNode *backgroundButtonNode = [SKSpriteNode spriteNodeWithTexture:dotTexture];
SKShapeNode *backgroundButtonNode=[SKShapeNode shapeNodeWithCircleOfRadius:0.5];
// backgroundButtonNode.size=ballSize;
backgroundButtonNode.userInteractionEnabled=NO;
backgroundButtonNode.zPosition=0;
backgroundButtonNode.fillColor=[UIColor whiteColor];
// backgroundButtonNode.colorBlendFactor=1.0;
backgroundButtonNode.position=[self.boardFrame convertPoint:CGPointMake(self.leftOffset+(self.gridSize*x)+self.ballSize/2,self.topOffset+(self.gridSize*y)+self.ballSize/2) fromNode:self];
[self.boardFrame addChild: backgroundButtonNode];
}
}
CGFloat menuiconsize=fmin(self.ballSize, 60.0);
CGFloat menuWidth=fmin(self.boardFrame.size.width-40,420);
if (self.menuBar != nil) {
[self.menuBar removeFromParent];
}
self.menuBar=[[MenuBar alloc]initWithSize:CGSizeMake(menuWidth,self.ballSize+12) iconSize:CGSizeMake(menuiconsize,menuiconsize) Level:self.level];
self.menuBar.delegate=self;
[self addChild:self.menuBar];
self.menuBar.position=CGPointMake(self.frame.size.width/2-(menuWidth)/2, self.topOffset-menuiconsize-40);
self.menuBar.userInteractionEnabled=YES;
self.gameOver=NO;
}
Code for the HUD (Stars, Goal...)
-(void) createHUD {
if (self.topHud == nil) {
self.topHud=[SKShapeNode shapeNodeWithRect:CGRectMake(-2,self.frame.size.height-62,self.frame.size.width+2,64)];
self.topHud.fillColor=[UIColor clearColor];
self.topHud.strokeColor=[UIColor clearColor];
self.topHud.lineWidth=0;
[self addChild:self.topHud];
UIColor *textColor=[self.level textColor];
self.scoreLabel=[SKLabelNode labelNodeWithFontNamed:@"Blow"];
self.scoreLabel.fontSize=20;
self.scoreLabel.alpha = 1;
self.scoreLabel.horizontalAlignmentMode=SKLabelHorizontalAlignmentModeRight;
self.scoreLabel.fontColor=textColor;
self.scoreLabel.position=CGPointMake(self.frame.size.width-8,self.frame.size.height-25);
self.score=0;
[self.topHud addChild:self.scoreLabel];
self.highScoreLabel=[SKLabelNode labelNodeWithFontNamed:@"Blow"];
self.highScoreLabel.fontSize=20;
self.highScoreLabel.alpha = 1;
self.highScoreLabel.horizontalAlignmentMode=SKLabelHorizontalAlignmentModeRight;
self.highScoreLabel.fontColor=textColor;
self.highScoreLabel.position=CGPointMake(self.frame.size.width-8,self.frame.size.height-50);
//self.highScore=0;
[self.topHud addChild:self.highScoreLabel];
[self updateScore];
self.doughLabel=[SKLabelNode labelNodeWithFontNamed:@"Blow"];
self.doughLabel.fontColor=textColor;
self.doughLabel.fontSize=20;
self.doughLabel.horizontalAlignmentMode=SKLabelHorizontalAlignmentModeCenter;
self.doughLabel.position=CGPointMake(self.frame.size.width/2, 20);
[self coinBalanceChanged:nil];
[self addChild:self.doughLabel];
self.progressNode=[SKCropNode new];
self.progressNode.zPosition=1;
SKNode *dimStarsNode=[SKNode new];
SKSpriteNode *maskNode=[SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(66,24)];
maskNode.position=CGPointMake(-42, 0);
// self.progressNode.maskNode=maskNode;
for (int i=0;i<3;i++) {
SKSpriteNode *starNode=[SKSpriteNode spriteNodeWithImageNamed:@"SugarCookie"];
starNode.size=CGSizeMake(20,20);
starNode.position=CGPointMake(i*22,0);
[self.progressNode addChild:starNode];
starNode=[SKSpriteNode spriteNodeWithImageNamed:@"SugarCookie"];
starNode.size=CGSizeMake(20,20);
starNode.zPosition=1;
starNode.alpha=0.3;
starNode.position=CGPointMake(i*22,0);
[dimStarsNode addChild:starNode];
}
self.progressNode.maskNode= maskNode;
// self.progressNode.maskNode=maskNode;
self.progressNode.position=CGPointMake(22, self.frame.size.height-18);
dimStarsNode.position=CGPointMake(22, self.frame.size.height-18);
dimStarsNode.zPosition=0;
[self addChild:dimStarsNode];
[self addChild:self.progressNode];
self.goalLabel=[SKLabelNode labelNodeWithFontNamed:@"Blow"];
self.goalLabel.fontSize=20;
self.goalLabel.alpha = 1;
self.goalLabel.fontColor=textColor;
self.goalLabel.position=CGPointMake(12,self.frame.size.height-50);
self.goalLabel.horizontalAlignmentMode=SKLabelHorizontalAlignmentModeLeft;
self.goalLabel.text=[NSString stringWithFormat:@"Goal: %ld",(long)self.level.targetScore];
[self addChild:self.goalLabel];
self.storeButton=[[GameButtonNode alloc]initWithColor:self.level.baseColor strokeColor:[self.level levelColorWithBrightnessDelta:0.3 alpha:1.0] imageName:@"store" radius:25 physics:NO delegate:self];
self.storeButton.position=CGPointMake(self.frame.size.width-40,35);
[self addChild:self.storeButton];
self.menuButton=[[GameButtonNode alloc]initWithColor:self.level.baseColor strokeColor:[self.level levelColorWithBrightnessDelta:0.3 alpha:1.0] imageName:@"menuButton" radius:25 physics:NO delegate:self];
self.bottomMenuNode=[SKShapeNode shapeNodeWithRect:CGRectMake(5, 30, 180, 60) cornerRadius:7.0];
self.bottomMenuNode.strokeColor=[UIColor clearColor];
self.bottomMenuNode.fillColor=[self.level levelColorWithBrightnessDelta:-0.6 alpha:0.2];
self.bottomMenuNode.zPosition=6;
self.homeButton=[[GameButtonNode alloc]initWithColor:self.level.baseColor strokeColor:[self.level levelColorWithBrightnessDelta:0.3 alpha:1.0] imageName:@"homeButton" radius:25 physics:NO delegate:self];
self.homeButton.position=CGPointMake(35,60);
[self.bottomMenuNode addChild:self.homeButton];
self.menuReplayButton=[[GameButtonNode alloc]initWithColor:self.level.baseColor strokeColor:[self.level levelColorWithBrightnessDelta:0.3 alpha:1.0] imageName:@"replayButton" radius:25 physics:NO delegate:self];
self.menuReplayButton.position=CGPointMake(95,60);
[self.bottomMenuNode addChild:self.menuReplayButton];
NSString *soundImage=[self soundImage];
self.soundButton=[[GameButtonNode alloc]initWithColor:self.level.baseColor strokeColor:[self.level levelColorWithBrightnessDelta:0.3 alpha:1.0] imageName:soundImage radius:25 physics:NO delegate:self];
self.soundButton.position=CGPointMake(155,60);
[self.bottomMenuNode addChild:self.soundButton];
self.bottomMenuNode.position=CGPointMake(0, 0);
self.bottomMenuNode.hidden=YES;
self.bottomMenuNode.xScale=0.1;
self.bottomMenuNode.yScale=0.1;
[self.menuButton addChild:self.bottomMenuNode];
self.menuButton.position=CGPointMake(40,35);
self.menuButton.zPosition=7;
[self addChild:self.menuButton];
}
}
Code for GameBoardNode
-(instancetype) initWithColor:(UIColor *)color strokeColor:(UIColor *) strokeColor imageName:(NSString *)imageName radius:(CGFloat)radius physics:(BOOL)physics delegate:(id<GameButtonNodeDelegate>)delegate {
if (self=[super init]) {
self.strokeColor=strokeColor;
self.ball=[SKShapeNode shapeNodeWithCircleOfRadius:radius];
self.ball.fillColor=color;
self.ball.strokeColor=strokeColor;
self.ball.lineWidth=3.0;
self.ball.zPosition=0;
self.touchDelegate=delegate;
[self addChild:self.ball];
self.icon=[SKSpriteNode spriteNodeWithImageNamed:imageName];
self.icon.size=CGSizeMake(30, 30);
self.icon.zPosition=0;
self.enabled=YES;
[self addChild:self.icon];
if (physics) {
self.physicsBody=[SKPhysicsBody bodyWithCircleOfRadius:radius ];
self.physicsBody.affectedByGravity=YES;
}
self.userInteractionEnabled=YES;
self.fadeIn=[SKAction fadeInWithDuration:0.3];
self.fadeOutRemove=[SKAction sequence:@[[SKAction waitForDuration:0.2],[SKAction fadeOutWithDuration:0.3],[SKAction removeFromParent]]];
}
return self;
}
LEVEL SELECT
The only issue with this view is the background image (blue gradient) appears and then fades away. The background image is set up in the storyboard.
Any other code or images, just ask.
How can I fix this problem and get my game working properly again?
Upvotes: 2
Views: 386
Reputation: 3812
iOS 9 cares more about zPosition than iOS 8 did. In the past if you didn't set the zPosition iOS8 would do a really good job of assuming what you wanted. In iOS9 it doesn't care and will render it however it wants.
I have also noticed leaving it at zero is also very bad. For instance if you have a node at 0 and add a child with a zPosition of 0...they both are 0 and iOS9 will pick which it should render first. If I am correct this should get your top hud showing back up again.
if (self.topHud == nil) {
self.topHud=[SKShapeNode shapeNodeWithRect:CGRectMake(-2,self.frame.size.height-62,self.frame.size.width+2,64)];
self.topHud.fillColor=[UIColor clearColor];
self.topHud.strokeColor=[UIColor clearColor];
self.topHud.lineWidth=0;
self.topHud.zPosition = 100;//added zPosition
[self addChild:self.topHud];
UIColor *textColor=[self.level textColor];
self.scoreLabel=[SKLabelNode labelNodeWithFontNamed:@"Blow"];
self.scoreLabel.fontSize=20;
self.scoreLabel.alpha = 1;
self.scoreLabel.zPosition = 1;//added zPosition
self.scoreLabel.horizontalAlignmentMode=SKLabelHorizontalAlignmentModeRight;
self.scoreLabel.fontColor=textColor;
self.scoreLabel.position=CGPointMake(self.frame.size.width-8,self.frame.size.height-25);
self.score=0;
[self.topHud addChild:self.scoreLabel];
self.highScoreLabel=[SKLabelNode labelNodeWithFontNamed:@"Blow"];
self.highScoreLabel.fontSize=20;
self.highScoreLabel.alpha = 1;
self.highScoreLabel.horizontalAlignmentMode=SKLabelHorizontalAlignmentModeRight;
self.highScoreLabel.fontColor=textColor;
self.highScoreLabel.position=CGPointMake(self.frame.size.width-8,self.frame.size.height-50);
self.highScoreLabel.zPosition = 1;//added zPosition
//self.highScore=0;
[self.topHud addChild:self.highScoreLabel];
Note 4 zPositions added. I hope that helps get things going in the right direction.
Upvotes: 2