【问题标题】:SK Scene transition backgroundSK场景过渡背景
【发布时间】:2013-10-06 10:14:17
【问题描述】:

我刚刚开始学习如何使用 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:我觉得奇怪为什么我必须将它缩放到 0.7,而背景实际上是 480x320 的尺寸。

【问题讨论】:

  • 1) 检查场景的 scaleMode 和 2) 检查初始场景的大小(应为 480x320)。后者是一个已知问题,即使应用程序仅支持横向 iOS 最初以纵向模式启动应用程序并将尺寸报告为纵向直到某一点(我认为 viewWillAppear)。检查初始场景是 480x320 还是 320x480。
  • 两个场景中的scalemode都是menu.scaleMode = SKSceneScaleModeAspectFill;

标签: ios7 xcode5 sprite-kit


【解决方案1】:

当您使用横向时,我会交换

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-07
    • 2020-05-25
    • 1970-01-01
    相关资源
    最近更新 更多