Xcode 7和IOS 9中的SpriteKit问题

时间:2015-10-15 10:30:17

标签: objective-c xcode sprite-kit ios9 skspritenode

我的游戏应用程序在IOS 8上运行完美(使用Xcode 6构建)在使用带有IOS 9的Xcode 7构建时突然遇到许多问题。 以下是游戏过去的样子。 (它应该如何看)。 Level Select Page Game Scene 这是在IOS 9上运行(坏了) Level Select Page Broken Game Scene Broken

游戏场景代码

在游戏场景中创建游戏板的代码

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

}

HUD代码(明星,目标......)

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

}

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

此视图的唯一问题是背景图像(蓝色渐变)出现然后消失。 背景图片在故事板中设置。

  • 大多数图片来自Images.xcassets文件夹。
  • 所有图片均为png。
  • Bitcode关闭(如果这有所不同)

任何其他代码或图片,请问。

如何解决此问题并让我的游戏再次正常运行?

1 个答案:

答案 0 :(得分:2)

iOS 9比iOS 8更关注zPosition。在过去,如果你没有设置zPosition,iOS8可以很好地假设你想要的东西。在iOS9中,它并不关心并且会根据需要进行渲染。

我也注意到把它留在零也很糟糕。例如,如果你有一个节点为0并添加一个zPosition为0的子节点......它们都是0,iOS9将选择它应该首先渲染的节点。如果我是正确的,这应该会让你的头衔再次显示出来。

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];

注4添加了zPosition。我希望这有助于让事情朝着正确的方向发展。