SpriteKit support different screen sizes - ios

I want to create the game like this. It is puzzle game.
My questions is do I need to have different images for each devices? So for now as we can see Apple has 5 different mobile devices sizes:
iPhone 3.5''
iPhone 4''
iPhone 4.7''
iPhone 5.5''
iPad
So my question is if I have assets for iPad retina, then I also need 4 other the same assets with backgrounds and puzzle images for iPhone sizes? Or I can optimize it? Like for example if we create 3d game, openGL renders just needed frame and we don't need as many scene as many devices we have, just one.

Detect devices and setup your assets like this.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 480)
{
// Setup iPhone 4, 4s, iPod Touch Assets
}
else
{
// Setup iPhone 5, 5s, 6 Assets
}
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
//Setup iPad Assets
}

There are many factors to consider when supporting different screen sizes. A big factor to consider is whether or not you want separate non-retina and retina (#2x) versions of your assets. You could decide to just use retina images and let them scale down on non-retina devices, but it would not be optimized because you would have the full textures loaded into memory.
The next factor to consider is the size of your assets. Are you planning on making the game have larger assets on larger devices? Or are you planning on keeping the assets all the same size but giving larger devices a larger viewport? (i.e. iPhone might have scrollable view while iPad wouldn't need to scroll because it would have a larger view)
The next factor to consider is the aspect ratio of your assets. You will certainly need different assets for when you aspect ratios differ (such as typically in the case of background images, splash screens etc.)
I recommend you use Apple's Images.xcassets folder. It will allow you to organize all of your assets across all the different devices. And for more information about scene scaling on different resolutions, I suggest you read my answer here

Related

How can I find the 'safe region' for iPhone size if I am creating my app using iPad size?

I am creating a game and want to use the iPad size settings (landscape: 1024x768). From what I've learnt, using the iPad settings will crop out part of the height only on an iPhone. Say I have a 2048x1536 background image for iPad (1024x768) and a 2208x1242 image for iPhone 6+ (736x414),
i. how can I determine the 'safe region' from the iPad that will appear on the iPhone 6+ both point and pixel wise?
ii. will the 'safe region' for the iPhone 6+ be the same as the iPhone 6 (667x375) with a 1334x750 image? If not, how can it also be determined both point and pixel wise?
I assume you wish to create a universal game that runs both on iPad and iPhone. If that's the case, there are two possible approaches when defining your graphics assets in the Attributes Inspector (far right on your Xcode interface while Assets.xcassets is selected). In the Devices section, you can select among Universal, iPhone, iPad, Apple Watch, Apple TV, Mac and any combination of those.
If you select "Universal" only, then you will have to make sure that the assets you insert there will look good both on iPhone and iPad. If that's the case, see below some hints of how to make your assets safe for using universally.
If you select "iPad" and "iPhone", you will have to include separate assets for iPad and iPhone, with their appropriate resolutions and aspect ratios. In my past experience, I've always headed this way. For the iPad (1x) you will have to provide a 1024x768 background, for the iPad (2x) you will have to provide a 2048x1536, unless you choose "Single Scale" and use a single vector PDF file. Respectively, for the iPhone, you will have to provide a 480x320 (1x, only in case you need to support old devices such as iPhone 3G/3GS, quite unlikely given the fact Sprite-Kit was introduced with iOS7), then 1334x750 (2x), and 2208x1242 (3x, for the iPhone 6+, 6S+, 7+). With this approach you don't need to worry about "safe" zones, as the graphics you supply will be used on each device properly with no "cutting" off the edge. Just bear in mind that iPhone 4S and iPhone 5/5S/SE would need some background scaling in order to fit the whole 2x picture on the screen. Otherwise it would look zoomed in.
If you go with the first approach, then you should consider the following information in order to make your "universal" graphics safe for use with all devices:
iPhone 5/5S/SE...and all newer have a 16:9 display aspect ratio.
iPhone 4S has 3:2 aspect ratio (you only worry about that if your game will support iOS 9).
iPad screen aspect ratio is 4:3.
With the above in mind, there are two paths you could go:
1. Use 16:9 universal assets that will have their left/right parts cut off on iPad and iPhone 4S.
2. Use 4:3 universal assets that will have their upper/lower parts cut off on iPhones.
The above applies to your 2x assets as these will be used for both retina iPads and retina iPhones (4S, 5/5S, SE, 6/6S/7).
1x assets will only be used for non-retina iPads (iPad 2 in case you would support iOS 9, otherwise skip these too).
3x assets will only be used for the "Plus" iPhone models. So I suggest you provide these in 16:9 ratio (2208x1242) only.
So, how do you calculate your "safe" zones. Pretty straightforward:
Case 1 (16:9 assets to be used for iPad too): height 1536 (this is the retina iPad height in pixels, although if you wish to be pixel-perfect on iPad Pro 12.9" then you should increase that to 2048), width = 1536 * 16 / 9 = 2732 pixels wide (3640 pixels for iPad Pro support). Note that you will have to scale it down in run-time in order to fit for the iPhones. In order to avoid cutting off important content from your background, don't put anything to the left or right of the middle 2048 pixels of the 2732x1536 universal image (342 pixel "danger" zones on the left and right). If you go with a 3640x2048 image (supporting iPad Pro 12.9"), then only use the middle 2732 pixels, leaving only unimportant stuff in the 454-pixel-wide left and right boundaries.
Case 1b (same as above but with a smaller image): Another approach would be to use a native (iPhone 6/6S/7) 1334/750 pixels image, but then you will have to scale up for iPads, and scale down for iPhone 4S/5/5S/SE. In this case, your "safe" zone is 1000x750 (visible both on 4:3 iPads and 16:9 iPhones).
Case 2 (4:3 assets to be used for iPhones too): For the 2x assets use 2048x1536 pixel images. Depending on how you position the sprite on the screen there will be loses on the upper and/or lower parts. If it's centered, then your "safe" zone is 2048 / 16 * 9 = 1152, which leads to 2048x1152 in the middle of the 2048x1536 asset.
If you need any further clarification I will be happy to elaborate.

iOS: Preparing background images for applications

Mostly every iOS application has a view with an image as background. Is there any image sizing guide out there? For example here is an iOS screen designed in Sketch:
As you can see there is a background image. Now there are lots of Apple devices every application should support. The new iOS 10 supports all devices from iPhone 5 to iPhone 6s Plus. They have different screen sizes and resolutions. When creating Xcode assets, I am giving 3 background images with different sizes - #1x, #2x, #3x. What sizes should they be?
The way I see it you have 2 options:
In here you will find the resolutions of the iPhone's:
You don't need the #1 image since you don't support iPhone 4 and 4s (iOS 10).
#2 is for iPhone 5,5c,5S,6 and 6s so basically you can create #2 image of the highest resolution which is the iPhone 6 and this image will work well for the iPhone 5 family.
Or, you can create an image with resolution for each iPhone and using hard coded logic set the image for each phone.
i.e: if iphone5c { setImage("iphone5cImage") } etc etc..
The simplest solution is to create 1 image with the highest resolution. The #3 is the highest for the iPhone 6S+ and it will look amazing for the rest. Don't forget to set the image view as aspect fill.
Also, don't forget to check this thread: How to handle image scale on all the available iPhone resolutions?. It will give you clues of what exactly you are dealing with. TL;DR, It's the options I wrote.
The background images you only need to give are #2x and #3x, because #1x devices are now long gone in the dusty pages of history.
Speaking of #2x and #3x, the image resolutions you give to the developer should be the same with the highest resolution iPhone that uses that given size.
For #2x, that is the iPhone 6, which is 750x1334, and for #3x, the iPhone 6+ which is 1242x2208.
Down-scaling shouldn't be a problem because the aspect ratios of all iPhones that support iOS 10 are the same(16:9).
Note for Developer(s):
The UIImageView will then down-scale the images appropriately,
provided:
1. you created an image set with the provided #2x and #3x images,
2. correctly constrainted the UIImageView to the edges of the superview, and
3. selected the Content Mode of the UIImageView as Scale to Fill or Aspect Fill.
There is design nuance in full size background images. Mostly if the scale aspect fill good enough for different sizes you need to design only for the biggest device size after that the rest of them scale to fit. Sometimes some part of background needs to remain visible or if want to keep a low memory footprint for small device sets you need to create smaller alternatives.
Whenever you make a decision with the design size of asset you need to create #3x,#2x variants.
One more thing I need to point out about vector designs. If your design is made only with vectors you can choose pdf vector export. Storyboards can accept vector assets and they are doing very good when scaling in full backgrounds.
I use background images in my Apps. To solve this problem I use one image that has the resolution to cover all iPhones and all the iPads except the large one.
The image size is 2048x2048 points or 1024x1024 pixels at #2x to cover the 9.7 inch iPad.
The image is compressed JPG to keep the size down. Note that I allow it to scale for iPhone 6 Pluse (#3x) and 12.7 inch iPad Pro (#2x) as the quality doesn't seem to be affected.
I can justify the scaling for the larger devices, because if I provided image for the 12.7 inch iPad Pro, it will be 5464x4096 points (#2x) and 2732x2048 pixels and then the JPG compression would have to be so high (if I wanted to keep the size down), that the quality of the image was low anyway compared with scaling.
If you need high quality try both JPG and PNG for comparison, because the PNG becomes very large for complex images, but gives the best quality.
If you still have the same problem then you can try this one. For this you have to add only one image with good resolution and below code..
UIImage *bgImage = [UIImage imageNamed:#"art_background_star#3x.jpg"];
CGSize screenSize = [UIScreen mainScreen].bounds.size;
UIGraphicsBeginImageContextWithOptions(screenSize, NO, 0.f);
[bgImage drawInRect:CGRectMake(0.f, 0.f, screenSize.width, screenSize.height)];
UIImage * resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIColor *backgroundColor = [UIColor colorWithPatternImage:resultImage];
self.view.backgroundColor = backgroundColor;
There are 3 kinds of Apple Devices (iPhone and iPad) that is
Normal device which terms to 1 pixel = 1 point#1x (Older iPhone and iPad devices)
Retina device which terms to 4 pixels(2 x 2) = 1 point#2x (iPhone 5+)
Retina iPhone6 and iPad which terms to 9 pixels (3 x 3) = 1 point#3x (iPhone6+)
For iOs 10 that will not support iPhone 4s so you only require #2x and #3x images.
As you can see above attached image iPhone 6 also support #2x Scale so use image size for #2x is of 750*1334 and for #3x is of 1242*2208 with image mode.
Take a look at the page on documentation, there is Static Launch Screen Images, and you can catch sizes from there.
You can get a device screen size, using
CGSize screenSize = [UIScreen mainScreen].bounds.size // (Objective-C)
let screenSize: CGSize = UIScreen.mainScreen().bounds.size // (Swift)
And after you can programmatically select an image you want, from set of an images from the bundle. Or to make a big one image for resizing, using knowledges from documentation, and to resize an image accordingly. Or...your choice.
Different "sizes" #2x, #3x is scale.
And here is the nice explanation.

Image resolutions to supply for adaptive iOS app

While developing an iOS app I invested a lot of time in making everything adaptive (size-classes and so on). I have implemented an few image scrollers / photo galleries that are screen wide and zoomable. What is the best practice related to multi-screen image storage and exposure?
It is not a problem to store or generate on the fly, let's say, five different resolutions for every image and load the best resolution depending on network connection and screen size. I want to know what is recommended for this sort of diversity.
This is a (perhaps incomplete) list of all the possible image resolutions based on screen size:
iPad landscape & portrait: 704px wide
iPad 2/3: 694px wide
iPad 1/2 landscape: 507px wide
iPad 1/2 portrait: 438px wide
iPhone 6+: 414px wide
iPhone 6: 375px wide
iPhone 4/5 + iPad split screen right-side: 320px wide
All my images are square. So height equals width.
Do I include retina photos or should I use #1x for photos? Do I add extra pixels for the zooming (1.5x max)?
This is are basically the current resolutions for iOS Devices.
Basically in the retina devices you need to provide #2x images if you want them to appear not pixelated. Also in the iPhone 6 Plus and 6s Plus you will need to provide #3x images.
In the following links you can find more information about it.
http://ivomynttinen.com/blog/the-ios-design-cheat-sheet-volume-2/
http://www.idev101.com/code/User_Interface/sizes.html

Using less Images for non-retina, retina and retina HD (#1x, #2x, #3x) for Universal Apps

To support iOS 7 to 8 on universal devices, I have to make 4 copies of the same image in different size.
For the iPhones
image#2x.png (iphone 4s,5,5s,6)
image#3x.png (iphone 6+)
For the iPads
image.png (ipad 2, ipad mini 1)
image#2x.png (ipad 3, 4, ipad mini 2, ipad Air)
The images are really bloating the app size.
Is it ok to just use 1 image size, the largest one of the set and scale to fit in the uiimageview and use the image view to scale down the image on the smaller screens?
imageView.contentMode = UIViewContentModeScaleAspectFit;
or is it absolutely necessary to have all 4 copies at different sizes?
It works on all the devices on the simulator and on a retina iPad 3, but I have no way of actual testing on other devices and am afraid that the images may not display.
Has anyone tried using 1 large image instead of the set of copies?
Yes, you can theoretically use the largest resolution image and have the UIImageView scale the image down using mode Aspect Fit.
The only drawback is the older phones that don't support retina also are less performant. For example, when using images on cells of a UITableView and scrolling, the device has to load the large image, then scale the image down, and scroll it at the same time, and it will stutter on old, slower devices.
So, perhaps just use multiple images in list views (should just be thumbnails and are tiny anyway, or just use the smaller images here), but don't worry about larger images that stay on the screen and don't scroll.
Make sure you load images in list views using methods that allow caching like imageNamed:.
As long as you take into consideration the performance penalties involved in scaling down the images, you can use just the largest image and scale it down to fit.
By the way, yes I've used this technique in real live apps in the App Store.
Another technique I've seen is to include lower quality images (1x or 2x) and if you run it on a higher resolution device (2x or 3x), automatically download high resolution images from the web. Maybe be nice about it and only download them on wifi.

Preparing assets for iphone 6 spritekit games

I'm making a game in SpriteKit, and positioning cards with code. The size of the card texture needs to be different based on screensize or the layout is screwed. Same with background images of course, or ANY other layout. How does the iphone6 share the same #2x assets with the lower-res screens? It makes no sense. I've heard to design for the 6, and let the older phones down scale. but this doesnt seem to be what is happening. Everything is just cut off when checking on 5s. My assets for 6+ are fine, but of course it uses its own set of 3x images.
Display scale factor doesn't tell you everything you might want for choosing assets and laying out your screen — e.g. if all you have are #2x assets, they're used on both iPhone (4 and newer) and iPad (3 and newer) even though the iPad and iPhone have very different screen sizes.
SpriteKit's image loading falls back to UIKit's, which automatically picks the right scale factor for your device but not the right dimensions. So, much like how you have to do your own heavy lifting to choose different images for iPhone 4/4s vs iPhone 5/5s, you'll also need to look at the screen size yourself to pick images and/or do layout calculations on 3.5", 4", and 4.7" displays.
(Actually, you can get UIKit to automatically pick iPhone 3.5" vs iPhone 4" images if you use Xcode asset catalogs, but it doesn't look like those cover the 4" vs 4.7" issue. That's probably worth filing a bug about.)

Resources