嗨,我是sprite kit框架的新手,我只想知道两件事:
1)如何在当前场景中获取所有SKSprite节点?
2)如何使应用程序通用,即它将在iPhone 3.5",iPhone 4"在iPad上?
提前谢谢。
答案 0 :(得分:6)
self.children
获取所有SKSprite节点答案 1 :(得分:0)
虽然答案的第二部分过于宽泛,但我可以理解您的来源,因为它有点压倒性地试图找出如何支持所有不同的屏幕尺寸。但对于遇到类似过于宽泛的问题的其他新开发人员来说,如果您只是想让您的场景适合不同的屏幕分辨率,并且暂时想要忽略多个图像分辨率和资产目录的概念,那么一个地方开始是处理场景的大小及其缩放模式:
在你的viewController中你可以做这样的事情。它有点沉重,但旨在显示区别:
//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];