Spritekit multiple device resolution detection - ios

I have backgrounds for iPhone 4s, 5, 6, 6plus, iPad, iPad retina. My question is how to distinguish them from each other since many are retina(#2x). Can I use the same filename for the background and add #2x, #3x? It seems to pick up the wrong backgrounds from the #2x ones when I do this(i,.e iPhone 5 on a iPad Retina). There must be an easier way then checking every single resolution and pulling that image. Clarity on this would be very helpful thanks!
In the scene itself I use
SKSpriteNode * MainMenuBackground;
MainMenuBackground = [SKSpriteNode spriteNodeWithImageNamed:#"Background1"];
so for the other devices can I do these filenames:
Background1#2x~iphone5.png (1334 x 750)
Background1#2x~iphone6.png (1136 x 640)
Background1#3x~iphone6plus.png (2208x1242)
Background1~ipad.png (1024x768)
Background1#2x~ipadRetina.png(2048x1536)

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.

Iphone6 and Iphone 6Plus Resolution #x2/#x3

I've a question about resolution of Iphone 6 and Iphone 6 Plus.
I would like to know something about #x2 and #x3, i really need to be sure !
If i've a fullscreen UIImageView, display on a Iphone 6(667x375 points) the size of the containing UIImage have to be 1334x750 because the size in points are 667(#x2)x375(#x2), right?
So if i understand, the UIImageView on Iphone 6Plus in fullscreen is 736x414 but the resolution is #x3 then the UIImage in the UIImageView have to be 2208x1242 because the size in points is 736(#x3)x414(#x3), no ?
Then in a general case, i only need to know what is the size of my UIImageView and if the resolution is #x2 i multiply the size x2 and if the resolution is #x3 multiply the size x3?
Guys i really need a confirmation and if i'm wrong, please, explain me why !
I'm sorry if you think my question is really stupid but i need to understand how it works.
Cordially :)
Lets go for a ride of #1x, #2x and #3x image scaling and content viewer size according to different resolutions in iPhone.
Let understand some basics first
Device Resolution
================================
iPhone 4 & 4S 640×960
iPhone 5, 5C & 5S 640×1136
iPhone 6s 750×1334
iPhone 6P 1242×2208
Resolution reference from this site.
Now if how to use images with #1x, #2x & #3x.
Lets say you have an imageView in with size of 100W x 100H, to display images properly on all the devices with appropriate resolution without stretching or pixelation your image, one need to create 3 set of images as below according to device.
iPad 2, iPad mini supports #1x images, required image of size 100x100(WxH)
iPad, iPad mini supports #2x images, required image of size 200x200(WxH)
iPhone 4S, 5 & 6 supports #2x images, required image of size 200x200(WxH)
iPhone 6P supports #3x images, required image of size 300x300(WxH)
Though your UIImageView size is 100x100 for all the devices, but image displayed in different devices is different according to their resolutions.
Following size Table will give you more clarification, read more about it in apple documentation here
I hope it clears confusion about different resolution images for different devices :)

Sprite Kit Scene Editor GameScene.sks scene width and height

I'm using the spritekit scene builder to build my scene (aka the GameScene.sks file when you create the project in xcode 7 ios9). SpriteKit only uses pixel values when setting the screen height and width. My question is this:
If I set the pixels values to that of an iphone 6, will the game be too small for ipad and iphone 6+? Why is there no option to fit the device screen? What should I do to avoid this?
Pixel density
First of all the size of the Scene is defined in Points not Pixels.
Let's see how the devices that support iOS 9 deal with this:
1 point = 1x1 pixel: iPad 2, iPad mini
1 point = 2x2 pixels: iPhone 4s, iPhone 5, iPhone 5c, iPhone 5s, iPhone 6, iPhone 6s, iPad mini 2, iPad mini 3, iPad mini 4, iPad 3,
iPad 4, iPad Air, iPad Air 2, iPad Pro, iPod touch 5, iPod touch 6
1 point = 3x3 pixels: iPhone 6 Plus, iPhone 6s Plus
This allow you to specify a size that is automatically converted for the pixel density of a particular device.
Screen size
There are several screen sizes available on the iPhone/iPad supported by iOS 9.
With SpriteKit you can easily face this problem setting the scaleMode property of your Scene.
You can chose among 4 options:
Fill: Scale the SKScene to fill the entire SKView.
AspectFill: Scale the SKScene to fill the SKView while preserving the scene's aspect ratio. Some cropping may occur if the view has a
different aspect ratio.
AspectFit: Scale the SKScene to fit within the SKView while preserving the scene's aspect ratio. Some letterboxing may occur if
the view has a different aspect ratio.
ResizeFill: Modify the SKScene's actual size to exactly match the SKView.
You probably want to set AspectFill but it really depends on your game.
To set the property open GameViewController.swift (or .m if you use Objective-C), in viewDidLoad you'll find this line. Just change it to mach your preference.
/* Set the scale mode to scale to fit the window */
gameScene.scaleMode = .AspectFill

Resizing an image without loss of quality for different screen sizes. What is the best way to go about it?

So I am currently having some images designed for my app (social stickers Facebook style/ Line) I'm not really sure what resolution the images should be. iPhone 5s is 320*568 pts so a perfect square panning the width of the screen would be 320*320 points and because 5s is retina that would be 640*640 pixels. Is that correct? For a pixel perfect image spanning the width it would be 640*640 pixels?
I saw that iPhone 6 plus is 414*736 pts which scales up by *3 so it's 1242*2208, so would a pixel perfect square spanning the width for the iPhone 6 plus be 1242*1242 pixels?
If I was to get my graphic artist to draw on a 1242*1242 canvas would I lose much quality scaling it down for the iPhone 6 and the iPhone 6 plus?
Not really sure how to go about this. Just want to make sure my square canvas rescales without loss of quality between the 6+,6 and 5. Any help would be greatly appreciated. Thanks!
When you rescale from higher pixels to lower pixels it never lose any quality, so in your case yes you must ask for iPhone 6+ size of images to your designer and you can rescale as per your need, you won't lose any quality for sure.
width for the iPhone 6 plus be 1242*1242 pixels?
Yes you are right, you will need 1242 x 1242 for iPhone 6+.
if you are making a universal app, you will need Retina and Unretina versions of each image for both iPad and iPhone. That is, four different images:
For every piece of art, you generate four sprites.
iPhone Unretina: image.png
iPhone Retina: image#2x.png
iPad Unretina: image-iPad.png
iPad Retina: image-iPad#2x.png
Except for backgrounds, make iPhone Retina art the same size as the iPad Unretina art.
Extract from this article: http://www.gameartguppy.com/how-to-size-game-art/

Resources