iOS SpriteKit 获取当前场景中的所有节点并使应用程序通用化。

7

你好,我刚接触 SpriteKit 框架,有两个问题想请教:


1) 如何获取当前场景中的所有 SKSpriteNode?
2) 如何制作通用应用程序,即在 iPhone 3.5 英寸、iPhone 4 英寸和 iPad 上运行?


提前感谢。

2个回答

7

3
你对问题1的回答似乎并没有真正回答问题,是这样吗?场景中的子节点也可以再次拥有子节点,因此self.children将不会给出场景中所有节点的完整列表,而只列出那些是场景的子节点... - NieLernend

0

虽然你回答的第二部分有些宽泛,但是我能理解你的观点,因为尝试支持所有不同的屏幕尺寸确实有点令人不知所措。但对于其他遇到类似过于宽泛的问题的新开发人员来说,如果你只是想让你的场景适应不同的屏幕分辨率,并且暂时不想考虑多个图像分辨率和资源目录的概念,其中一个起点是处理你的场景大小和比例模式:

在你的视图控制器中,你可以这样做。这有点笨重,但旨在显示区别:

//we'll set what we want the actual resolution of our app to be (in points)
//remember that points are not pixels, necessarily
CGSize sceneSize = CGSizeMake(320, 568);

//check if this is an ipad, this means the screen has 2x the points
//it also means that the resolution is different than the iphone 5
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    sceneSize = CGSizeMake(sceneSize.width * 2, sceneSize.height * 2);
}


SKView *skView = (SKView*)self.view;
self.mainPrimaryScene = [[PrimaryScene alloc] initWithSize: sceneSize forSKView:skView];

//by setting the scale mode to fit, it takes the size of the scene
//and ensures that the entire scene is rendered on screen, in the correct ratio
self.mainPrimaryScene.scaleMode = SKSceneScaleModeAspectFit;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
//you can check out all the other scale modes if you want to fill, etc
    mainPrimaryScene.scaleMode = SKSceneScaleModeResizeFill;

}

[skView presentScene:mainPrimaryScene];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接