0

我刚刚开始学习如何使用 xCode 尤其是新的 SpriteKit 进行编程。所以请记住,我对此有点陌生。

我设法通过按标签移动到不同的场景,但不知何故,我的场景背景完全出错了。背景应该和第一个场景一样,但它给了我一个带有两条单杠的背景。我认为我没有做错任何事,因为我刚刚复制了将背景设置为第二个场景所需的代码。

第一个场景:http: //imageshack.us/photo/my-images/23/kyud.png/

第二场:http: //imageshack.us/photo/my-images/198/472h.png/

我的代码用于设置两种背景:

SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"background_start"];
    background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
    background.xScale = 0.7;
    background.yScale = 0.7;
    [self addChild:background];

过渡通过以下方式完成:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

if([node.name isEqualToString:@"startgame"]){
    Options_Scene *gs = [[Options_Scene alloc] initWithSize:self.size];
    SKTransition *doors = [SKTransition doorsOpenVerticalWithDuration:0.5];
    [self.view presentScene:gs transition:doors];
}

}

PS:当背景实际尺寸为 480x320 时,为什么我必须将其缩放到 0.7,我觉得很奇怪。

4

1 回答 1

0

当您使用景观时,我会交换

viewWillAppear

- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];

SKView * skView = (SKView *)self.view;

if (!skView.scene) {
    //skView.showsFPS = YES;
    //skView.showsNodeCount = YES;
    // Create and configure the scene.
    SKScene * scene = [PMyScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;
    // Present the scene.
    [skView presentScene:scene];
}
}
于 2013-10-02T07:55:27.690 回答