I am trying to make a game using sprite kit that works on both iPhone and iPad.
For iPhones I can set the scene size to 320x568 and scale it for all resolutions it works fine.
For iPads too this works fine. But as the point resolution on iPad is 768x1024 I can see scaling artifacts and also images are not sharp.
So I want to set the scene size to 768x1024 for iPads. Most of my game images are drawn using sprite kit instead of loading images. So when I set the new scene size the images look smaller.
What would be the best way to specify the correct dimensions for the images while drawing it? Would I have to convert each and every dimensions and points used based on the device type?
You can draw your images using the largest screen size and scale them down to fit smaller screen sizes. This works well if the aspect ratio is the same for devices like iPhone 5, 6 and 6+. You do have to create separate images and/or screen layouts for the iPad and iPhone 4 which have a different aspect ratio.
Related
I am creating an iOS game using sprite kit scene. My sprite kit scenes are sit to a scale value of x = 1136 by y = 640, creating a horizontal game play. This resolution adjusts to all iPhones up to iPhone 8. However iPhone X and iPhone 11 have a different aspect ratio for their screen resolutions than the other iPhones. I was wondering if there is a setting or something that can be done programmatically to adjust the set game cg points and image sizes to adjust to the iPhone X and iPhone 11 without individually changing cg points of all images and image scales in code.
I figured it out. You can manually change the aspect ration to adjust to the device being used. To figure out the right aspect ratio you need use this link https://developer.apple.com/reference/spritekit/skscenescalemode
I am in the process of learning iOS development with XCode. I created a project to implement some of the things I've been learning and to begin learning how to manage image sizes and placement on different sized screens i.e. iPhone 8, iPhone 8+, iPad, etc. I am currently using XCode 10 Beta and I noticed that the View size on the main storyboard is half the actual screen size of any device I select to to View As:. For instance if I select View As: iPhone 8 the screen size is 375x667 instead of being 750x1334 like the actual device. I discovered this because I created a square image of 100x100px and thought I would be able to line up 7 across the screen. To my surprise the images took up twice as much screen as I had calculated.
Can anyone let me know why the screen Views in XCode are half that of actual screen size?
Do I just always assume to make my graphics half the size I would actually want them?
Edit: Here's a screenshot of what I am referring to in XCode
When I click on the empty view in the the XCode storyboard pane this is this resolution it displays for the view. Also, when I export my graphics from Illustrator the are exported with the #1x, #2x, and #3x variants. However, when I place an image in the view that is 100x100px it takes up about 1/3 of the screen instead of 1/7 of the screen as I would expect on a iPhone 8 which has a resolution of 750x1334.
Edit #2: So after playing around more with XCode I do see that the resolution for the views are in Points not pixels however, in this screenshot for a iPhone 8+ View:
I would assume with a screen resolution of 1080x1920 #3x the Point resolution would be 360x640 for an iPhone 8+ not 414x736.
It has to do with the difference between points and pixels. On the original iPhone when it was release it was 1 point per pixel but as resolution got better it became 2x pixels per point (4 pixels). Now the resolution is 3x pixels per point on some of the newer devices (9 pixels).
https://www.google.com/amp/s/blog.fluidui.com/designing-for-mobile-101-pixels-points-and-resolutions/amp/
So I am creating a Sprite Kit game and I want to have the same look on every device(no iPad, for now), as if it was the same scaled image.
So far I have my background images figured, 4 images for every screen size, chosen at runtime by checking the height of the screen. All my other images are designed for iPhone 6 plus, so I have #3x and #2x(66.6% of the #3x original image), that means I have iPhone 6 plus and iPhone 6 pixel perfect images.
The problem: Ran on iPhone 5/5s or 4/4s the images don't change size, they are as big as on iPhone 6, which is normal, they use the #2x. I want the images to scale by screen size. I know I have 2 options: use 4 sizes for every single image or scale the images by "screen height" / 667(iPhone 6). Both solutions are not good, because the first makes the app bigger and the second involves checking if it is iPhone 6 plus(use the #3x) and then scaling every single image, also both add a lot of code, I strive for clean code.
The first solution is acceptable, only if there is no other. Sorry for the long explanation, just want you to know what's going on.
I'm little bit confused by points in cocos2d.
I have universal game and when I set possition of body in points, it works well over all devices (iPhone, iPhone HD, iPad, iPad HD). I made textures in 4 sizes with cocos2d suffix and it works well too.
But I have body (b2CircleShape) and i need to set m_radius of this circle.
I have this lines:
b2CircleShape myDynamicBody;
myDynamicBody.m_radius=0.48;
Value 0.48 is optimized for iPhone HD and it works well on both iPhone (iPhone and iPhone HD) but on iPad and iPad HD devices it is very small. What should I do? Check type of device and when I find iPad multiply it in 1.33 (when I tried to multiply it in 1.33 it worked fine on both iPads).
Or is there any better (or recomended) way, how to solve this problem?
Thank you for advices
You should adjust your points-to-meter (PTM_RATIO) on iPad.
The reason for 'points', is that Box2d is tuned to run physics simulations for bodies between 0.1 and 10 meters, with a typical body being about 1x1 meter. It will still work for bodies outside of these sizes, but will be less reliable.
On the other hand, you've got a screen with either ~320x480 or 1024x768 points of resolution. Therefore we need a way to convert the sprite representation to a size that is suitable for Box2d. For this we use the 'points-to-meter' ration (PTM).
If your typical sprite is 64x64 you should choose a PTM ratio of 64. This will make box2d see you 64x64 sprite as 1x1, which is an ideal size to run simulations on it.
Having explained that, the reason that the PTM_RATIO varies between phone and pad form factors is now obvious: Its because they have different resolutions. A sprite that is 64x64 on iPhone would be approx 128x128 on tablet.
So to get your PTM_RATIO on ipad, choose a sprite on iPhone and look at the corresponding size on iPad. Now multiply the iPhone PTM by the ratio of the sizes beteen those two images.
When creating a simple HelloWorld Box2d template from cocos2d 2.0, the splash screen shrinks to half its normal size (after the flash). Its then as if every sprite is smaller. Is this normal?
Have you enabled Retina display mode? (It's on by default)
Did you add high resolution images (with -hd suffix) to your project?
If not, you'll notice all sprites being 50% smaller on a Retina display device because cocos2d is displaying the SD images on a Retina resolution surface. Either add -hd images that are twice as high and wide, or disable Retina display mode (look in AppDelegate.m).