如何在通用Sprite Kit游戏中调整Sprite的大小 [英] How do I size sprites in a universal sprite kit game

查看:162
本文介绍了如何在通用Sprite Kit游戏中调整Sprite的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对快速编程还比较陌生.我制作了一个不使用SpriteKit的应用程序,并且通过将图像缩小到屏幕宽度和高度的倍数来调整大多数视图的大小.不知道这是否是最好的策略,但是它奏效了,我能够构建一个在所有设备上看起来都不错的应用程序.

I'm relatively new to swift programming. I have made an app where I didn't use SpriteKit and I would size most views by scaling down the images to a multiple of the screens width and height. Not sure if this is the best tactic, but it worked and I was able to build an app that looked good on all devices.

使用spritekit和scene.sks文件时,我无法像以前一样选择自动布局来调整sprite的大小.在线上关于通用应用程序的内容并不多,所以我正在努力寻找解决方案.

With spritekit and the scene.sks files, I don't have the option of auto-layouts to size my sprites like I did before. There isn't a lot of content about universal apps online, so I'm struggling to find a solution.

我的问题是如何确定对象的大小并确保我的场景在不同设备上看起来相同?

My question is how do I go about sizing objects and making sure my scenes look the same across different devices?

如果您有一个很好的例子可以解释这一点,那将非常有帮助.谢谢!

If you have a good example that could explain this that would be very helpful. Thank you!

推荐答案

在SpriteKt中,我们通常要做的是给SKScene一个固定的大小,然后让SpriteKit在不同的设备上为您进行缩放.

What we usually do in SpriteKt is to give the SKScene a fixed size and let SpriteKit do the scaling for you on different devices.

所以基本上我们有2种正确的方法

So basically we have 2 ways to do it correctly

1)将场景尺寸设置为iPad(例如1024x768-风景,768x1024-纵向).这是Xcode 7中的默认设置.

1) Set scene size to iPad (e.g 1024x768 -landscape, 768x1024 - portrait). This was the default setting in Xcode 7.

您通常会在iPad的顶部/底部(横向)或左侧/右侧(纵向)/显示一些额外的背景,这些背景会被iPhone裁剪掉.

You than usually just have/show some extra background at the top/bottom (landscape) or left/right (portrait) on iPads which gets cropped on iPhones.

在iPad上显示更多内容/在iPhone上显示更多内容的游戏示例:

Examples of games that show more on iPads / crop on iPhones:

Altos Adventure,Leos Fortune,Limbo,The Line Zen,Modern Combat 5.

Altos Adventure, Leos Fortune, Limbo, The Line Zen, Modern Combat 5.

2)苹果将xCode 8中的默认场景大小更改为iPhone 6/7(750 * 1334-Portait,1337 * 750-Landscape).此设置将在iPad上裁剪您的游戏.

2) Apple changed the default scene size in xCode 8 to iPhone 6/7 (750*1334-Portait, 1337*750-Landscape). This setting will crop your game on iPads.

在iPad上显示较少的游戏示例:

Examples of games that show less on iPads:

Lumino City,机器人独角兽攻击

Lumino City, Robot Unicorn Attack

这两个选项之间的选择取决于您,具体取决于您制作的是哪种游戏.我通常更喜欢使用选项1,并在iPad上显示更多背景.

Choosing between those 2 options is up to you and depends what game you are making. I usually prefer to use option 1 and show more background on iPads.

无论场景大小缩放模式如何,通常最好将其保留为.aspectFill的默认设置.

Regardless of scene size scale mode is usually best left at the default setting of .aspectFill.

您将使用通用资产插槽和/或设备特定的图像.这样,您将在所有设备上获得一致的体验

You would use the Universal asset slot and/or device specific images. This way you will have a consistent experience on all devices

Spritekit将完整游戏扩展到iPad

如何使SKScene具有固定宽度?

希望这会有所帮助

这篇关于如何在通用Sprite Kit游戏中调整Sprite的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆