Sprite Kit创建一个新屏幕(重启方法)

时间:2015-04-26 00:42:57

标签: xcode uiviewcontroller sprite-kit

当我点击屏幕右侧(self.frame.size.width)的显示侧到中心(self.frame.size.width / 2)时,我正在测试我的游戏方法。你再次点击它回到(self.frame.size.width)(屏幕外)

而不是在我的重置方法中更改所有变量我想创建同一场景的新场景。

        GameScene* NewScene = [GameScene sceneWithSize:self.view.bounds.size];
        NewScene.scaleMode = SKSceneScaleModeAspectFill;

        [self.view presentScene:NewScene];

我的viewcontroller

 scene.scaleMode = SKSceneScaleModeAspectFill;

它有效但(假设它不在屏幕上)并且它的尺寸也增加了。

enter image description here

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self gameover];
if(direction == 1){
[self reset];
}

[self endInterFace];

for (UITouch *touch in touches) {
    location = [touch locationInNode:self];
}

[self handleDirectionChange];


}

 -(void)gameover{


    [score_Display runAction:[SKAction moveTo:CGPointMake(self.frame.size.width/2, self.frame.size.height/2+50) duration:0.30]];
    [ScoreFINAL runAction:[SKAction moveTo:CGPointMake(self.frame.size.width/2, self.frame.size.height/2+50) duration:0.30]];
    [highScoreFINAL runAction:[SKAction moveTo:CGPointMake(self.frame.size.width/2, self.frame.size.height/2-35) duration:0.30]];
    [score_Retry runAction:[SKAction moveTo:CGPointMake(self.frame.size.width/2, self.frame.size.height/2-120) duration:0.40]];
    [score_Rate runAction:[SKAction moveTo:CGPointMake(self.frame.size.width/2, self.frame.size.height/2-220) duration:0.55]];
    [score_Share runAction:[SKAction moveTo:CGPointMake(self.frame.size.width/2, self.frame.size.height/2-300) duration:0.75]];


}

-(void)reset{

    [score_Display runAction:[SKAction moveTo:score_DisplayXY duration:0.30]];
    [ScoreFINAL runAction:[SKAction moveTo:CGPointMake(self.frame.size.width, self.frame.size.height/2+50) duration:0.30]];
    [highScoreFINAL runAction:[SKAction moveTo:CGPointMake(self.frame.size.width, self.frame.size.height/2-35) duration:0.30]];
    [score_Retry runAction:[SKAction moveTo:score_RetryXY duration:0.40]];
    [score_Rate runAction:[SKAction moveTo:score_RateXY duration:0.55]];
    [score_Share runAction:[SKAction moveTo:score_ShareXY duration:0.75]];



GameScene* NewScene = [GameScene sceneWithSize:self.view.bounds.size];
NewScene.scaleMode = SKSceneScaleModeAspectFill;

[self.view presentScene:NewScene];

}

2 个答案:

答案 0 :(得分:1)

正如评论中所述,问题是由于宽高比

,视图可能会失真

溶液:

替换

GameScene* NewScene = [GameScene sceneWithSize:self.view.bounds.size];

使用

GameScene* NewScene = [GameScene sceneWithSize:self.frame.size];

答案 1 :(得分:0)

self.frame.size而不是self.view.bounds.size