SK场景过渡背景

时间:2013-09-30 13:55:49

标签: ios7 xcode5 sprite-kit

我刚刚开始学习如何使用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。

1 个答案:

答案 0 :(得分: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];
}
}