问题描述
我在 Xcode 中有一个基于 Objective-C 的项目.我正在尝试在视图控制器中添加一个 SpriteKit 场景作为一个较小的视图.不过 SpriteKit 文件很快.我添加了 Floor1.sks 并将其与 Floor1.swift 链接.
I have an Objective-C based project in Xcode. I'm trying to add a SpriteKit scene as a smaller view in a view controller. The SpriteKit files are in swift though. I've added Floor1.sks and linked it with Floor1.swift.
现在我正在尝试将它加载到我的 Objective-C ViewController.m 文件中.在我的故事板中,我创建了 SKView 类的视图,我认为我正确地创建了一个桥接头文件.我现在插入它的代码是:
Now I'm trying to load it into my Objective-C ViewController.m file. In my storyboard I made the view to the class SKView, and I think I properly made a bridging-header file. My code to insert it at the moment is:
GKScene *scene = [GKScene sceneWithFileNamed:@"Floor1"];
Floor1 *sceneNode = (Floor1 *)scene.rootNode;
sceneNode.scaleMode = SKSceneScaleModeAspectFit;
SKView *skView = (SKView *)_skView;
[skView presentScene:sceneNode];
skView.showsFPS = YES;
skView.showsNodeCount = YES;
当我成功运行应用程序时,视图会加载,但它只是一个带有浅灰色背景的空视图,节点数为 0,FPS 为 0.我做错了什么,为什么它不会加载我的正确视图?
The view loads when I run the app successfully, but it's just an empty view with a light grey background with the node count which is 0, and the FPS. What am I doing wrong, how come it won't load my proper view?
推荐答案
我遇到了同样的问题.原谅我的英语,我使用谷歌翻译.当我创建一个新的跨平台游戏时,我决定将其视为书面文件.即跨平台.它没有太多其他场景初始化.这一切都对我有用.过去仅适用于 iOS 10,现在适用于 iOS 9.我附在他们身上的截图
I had the same problem. Forgive my english, i use google translator.I decided to look at it as written files when I create a new cross-platform game. Namely cross-platform. It does not have much other scene initialization. And it all worked for me. Used to work only on iOS 10, and now iOS 9.Screenshots I attached to them
#import "GameViewController.h"
#import "GameScene.h"
@implementation GameViewController
- (void)viewDidLoad {
[super viewDidLoad];
GameScene *scene = [GameScene newGameScene];
// Present the scene
SKView *skView = (SKView *)self.view;
[skView presentScene:scene];
skView.ignoresSiblingOrder = YES;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
}
[GameScene.m][2]
[GameScene.m][2]
#import "GameScene.h"
@implementation GameScene {
SKShapeNode *_spinnyNode;
SKLabelNode *_label;
}
+ (GameScene *)newGameScene {
// Load 'GameScene.sks' as an SKScene.
GameScene *scene = (GameScene *)[SKScene nodeWithFileNamed:@"GameScene"];
if (!scene) {
NSLog(@"Failed to load GameScene.sks");
abort();
}
// Set the scale mode to scale to fit the window
scene.scaleMode = SKSceneScaleModeAspectFill;
return scene;
}
[GameScene.h][3]
[GameScene.h][3]
#import <SpriteKit/SpriteKit.h>
@interface GameScene : SKScene
+ (GameScene *)newGameScene;
@end
这篇关于Swift SKScene 在 Objective-C 项目中显示为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!