你好,我刚接触 SpriteKit 框架,有两个问题想请教:
1) 如何获取当前场景中的所有 SKSpriteNode?
2) 如何制作通用应用程序,即在 iPhone 3.5 英寸、iPhone 4 英寸和 iPad 上运行?
提前感谢。
你好,我刚接触 SpriteKit 框架,有两个问题想请教:
1) 如何获取当前场景中的所有 SKSpriteNode?
2) 如何制作通用应用程序,即在 iPhone 3.5 英寸、iPhone 4 英寸和 iPad 上运行?
提前感谢。
self.children
获取所有的 SKSprite 节点。虽然你回答的第二部分有些宽泛,但是我能理解你的观点,因为尝试支持所有不同的屏幕尺寸确实有点令人不知所措。但对于其他遇到类似过于宽泛的问题的新开发人员来说,如果你只是想让你的场景适应不同的屏幕分辨率,并且暂时不想考虑多个图像分辨率和资源目录的概念,其中一个起点是处理你的场景大小和比例模式:
在你的视图控制器中,你可以这样做。这有点笨重,但旨在显示区别:
//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];