次の動作を理解するのを手伝ってください(iOS Sprite Kit)。
以下に示すコードの出力は次のとおりです。
1.skView.bounds.size = 768.00、1024.00
2.skView.bounds.size = 1024.00、768.00
上記のように、幅と高さが 2 つの方法の間で入れ替わっているため、2 番目のシーンが正しい縮尺で表示されません。
私のゲームはランドスケープ モードでのみ実行されます。つまり、実際には、2 番目の幅 x 高さの比率が正しいことを意味します (ただし、シーンを正しいアスペクト比でレンダリングするのは最初のものであり、それ自体が謎です)。 .
この動作を修正する方法を誰か教えてもらえますか? 私は何を間違っていますか?
- (void)viewDidLoad
{
[super viewDidLoad];
self.currentGameState = GS_INTRO_SCENE;
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
printf("1.skView.bounds.size = %.2f, %.2f\n", skView.bounds.size.width, skView.bounds.size.height);
SKScene *scene = [SKTGameIntroScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (self.currentGameState == GS_INTRO_SCENE) {
self.currentGameState = GS_GAME_PLAY;
SKView * skView = (SKView *)self.view;
printf("2.skView.bounds.size = %.2f, %.2f\n", skView.bounds.size.width, skView.bounds.size.height);
SKScene *nextScene = [SKTMyScene sceneWithSize:skView.bounds.size];
nextScene.scaleMode = SKSceneScaleModeAspectFill;
SKTransition *fadeIn = [SKTransition fadeWithDuration:5.0f];
[skView presentScene:nextScene transition:fadeIn];
}
}
あらかじめご了承ください。
** 編集: **
@giorashc は、シーンの開始を -(void)viewWillLayoutSubviews メソッドに移動することを提案して私の問題を解決しました。
しかし、私の 2 番目のシーンは引き伸ばされたままです.... 変更後の SKTViewController.m の完全なコードは次のとおりです (2 番目のビューがまだ引き伸ばされている理由は誰にもわかりますか?):
//
// SKTViewController.m
// SpriteKitTest
//
// Created by Claudia Dazcal on 13/07/14.
// Copyright (c) 2014 DazcalFamily_inc. All rights reserved.
//
#import "SKTViewController.h"
#import "SKTMyScene.h"
#include "SKTGameIntroScene.h"
typedef enum
{
GS_INTRO_SCENE,
GS_GAME_PLAY
}GameStates;
@interface SKTViewController ()
@property GameStates currentGameState;
@property BOOL firstSceneLoaded;
@end
@implementation SKTViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.currentGameState = GS_INTRO_SCENE;
self.firstSceneLoaded = NO;
}
-(void)viewWillLayoutSubviews
{
if (!self.firstSceneLoaded) {
self.firstSceneLoaded = YES;
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
printf("1.skView.bounds.size = %.2f, %.2f\n", skView.bounds.size.width, skView.bounds.size.height);
SKScene *scene = [SKTGameIntroScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (self.currentGameState == GS_INTRO_SCENE) {
self.currentGameState = GS_GAME_PLAY;
SKView * skView = (SKView *)self.view;
printf("2.skView.bounds.size = %.2f, %.2f\n", skView.bounds.size.width, skView.bounds.size.height);
//CGSize DebugSize = CGSizeMake(skView.bounds.size.height, skView.bounds.size.width);
//SKScene *nextScene = [SKTMyScene sceneWithSize:DebugSize];
SKScene *nextScene = [SKTMyScene sceneWithSize:skView.bounds.size];
nextScene.scaleMode = SKSceneScaleModeAspectFill;
//SKTransition *fadeIn = [SKTransition fadeWithDuration:5.0f];
//[skView presentScene:nextScene transition:fadeIn];
[skView presentScene:nextScene];
}
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
@end
* 編集 2 **
わかりました、これですべてが整理されました。
@giorashc は、シーンの開始を viewWillLayoutSubviews に移動することを提案したとき、すぐに私の問題を解決しました。以前は間違った境界で作業していたので、間違った値で元のシーンを設定しましたが、修正されたので引き伸ばされたように見えました。
でも今は治りました。@giorashc ありがとうございました!!