iPhone display: Are image assets sharper then custom drawing? - iphone

The title mostly says it all;
I've got some mockups i am looking at, and as I try to implement them, It seems as though the custom drawing, even with a linewidth of 0.5, is not quite as sharp as the mockup appears when i preview it on my device. Can assets be sharper then what is possible to manually draw using quartz?

Can assets be sharper than what is possible to manually draw using quartz?
No. If that were the case, the iOS graphics system would be spectacularly broken.
Perhaps if you showed your custom drawing code, and an image of what it outputs, we could suggest something. Also, are you working with a "Retina" device?

This is most likely because of the resolution of the screen. The MacBook Pro and iMac without Retina display have approximately 110 pixels per inch and with Retina about 220, whereas the iPhone with Retina has 326 pixels per inch.
When you do coordinates in points and use whole numbers, it is as if the iPhone is 158 pixels per inch (meaning a width of 1 will be 1/158 inches wide) while on your computer it is most likely 110 pixels per inch (which is about 1/110 inches wide). However, since you are using a width of 0.5, a non-retina screen will stay at the same resolution as a width of 1.0 would be, however your device, which is most likely retina, is displaying a line with a width of 0.5 points, which is one pixel.
Because of this, a line with a width of 0.5 points will be 1/326 inches on a Retina device, but will be about 1/110 inches on your computer, which means that the line on the device will be about 3x sharper.

Related

SpriteKit - Can't understand what size to make background

I am completely confused on how to correctly size my lans background image which is landscape based. As of right now I'm doing GameScene(size: self.frame.size) and I print out the size of the screen so I know what size to make my background and it turns out my background should be 1024x768 but that doesn't seem like landscape dimensions? So I made my background 1024x768 but the entire image doesn't fit into my iphone when its landscape because the iphone lanscape dimensions arent 1024x768. How do I make a background that will look 1:1 with the dimensions of my iphone? The only way I can think is if I set the GameScene(size: CGPoint(x: 1334, y: 750)) but then wont it be screwed up for any other device? What's the best way to approach this? I have an artist who is going to make a background for me but I have no idea what dimensions to give him.
When dealing with scenes for Sprite Kit, try not to focus on the screen size, because screen size is no longer a factor (now this is not 100% absolute fact, this is a general rule to go by)
Instead, treat your SKScene as if it was a virtual screen. The size of your SKScene is the "resolution" of your SKScene, and the OS will work in the background to figure out how to convert 1 virtual pixel (From here on out we will call point) to screen pixels( referred to here on out as pixels)
Now there is only 1 special case where the OS will change the resolution (scene size) to match the screen, and that is .resizeFill The other 3 will never change resolution on you.
.aspectFill and .aspectFit will ensure that your point to pixel conversion keeps and equal width and height (e.g. 1 point could equal 4x4 pixels) The only difference is .aspectFill will expand to fill the entire screen, meaning that excess points will be rendered outside the native screen bounds [ so (0,0) may lie 20 pixels left of the left most pixel, thus not being visible] and .aspectFit will fill till it hits a screen border, leaving black bars to fill the unused pixels.
Now .fill does not keep and equal width and height point to pixel ratio, and in the case of a 4:3 going to a 16:9 screen, you will notice that your point to pixel will be 5:4 because a 16:9 screen is 25% wider than a 4:3. This gets you the fatty effect.
So when dealing with your game you need to figure out the desired effect. If you set your scene size to 1024x768, then all non retina iPads will have a 1:1 pixel to point ratio, where retina has 2:1 pixels to point ratio. For an iphone 5, you would get roughly 1.14 pixels to every point (iphone is 1168 and your scene is 1024, so you do 1168/1024) then of the 768, you would be loosing 25%, because the ipad is 25% taller than an iphone in landscape. This means only 576 points will be showing, and the rest are in invisible screen space.
Basically, you can never get a 1:1 with both an iPad and an iPhone doing a universal app because you are working with 2 different aspect ratios. You are going to have to make 2 different sets of assets, or take some creative liberties that doesn't alter the gaming experience. This depends entirely on the game and unfortunately nobody will be able to answer it till they have an understanding of your game.

How to handle resolution change 320x480 => 640x960 related to gameplay

I have decided to have 2 set of images for my iPod game. One with 320x480 and the other for the retina one. I can switch happily between them but this forces me to add extra code to handle the change in resolution.
My game is played in screen space on a grid, so, if I have 32 pixel tiles, I will have to use 32 offsets in low res and 64 in retina (because of doubling resolution). For a simple game this can be no problem, but what about other more complex games? How do you handle this without hardcoding things depending on the target resolution.
Of course an easy way to bypass this is just releasing a 320x480 version an let the hardware upscale, but this is not what I want because of blurry images. I'm a bit lost here.
If you have to, you can do the conversion from points to pixels (and vice versa), easily by either multiplying or dividing the pixel/point position with the contentScaleFactor of your view. However, normally this is done automatically by you if you just keep it to using points instead of pixels.
This is automatic. You only need to add image files suffixed '#2x' for the retina resolution.
Regarding pixels, from your program you work in points which are translated to pixels by the system. Screen dimensions are 320x480 points for iphone retina and non-retina.

How to draw rullar in iphone sdk?

Hi I want to make rullar in iphone.
Que: How to draw lines through UILabel in scrollView 1 inch. or 1 cm. apart from each other.
I know there are 163 pixels per inch(ppi). in 480-by-320-pixel.
But I am not sure about all version of iPhone .
Does the size of pixels are same for all its model???
Drawing in iOS uses point values rather than pixels; in a retina display there are four pixels (2x2) in a point and in a non-retina display there is one. The screen sizes are the same (with the obvious exception of the iPads). If you draw a line from (0,0) to (0,100) it will be the same length on the screen of the iPhone 4 and iPhone 3GS.

iPhone 4 screen resolution (code-wise)?

I had an epiphany just now.
In some places in my very first iPhone app I have hardcoded values referring to the screen width and/or height (320, 460).
now I realize that i never noticed this because in the iPhone 4 simulator i dont notice any drawing issues.
So does this mean the iPhone 4 internally converts 320 to be whatever the width for its screen resolution? i doubt it. But then again, why would i be seeing everything appearing to be fine when i run?
Example:
If I make a ball draw at position (320, 100) I can clearly see that it is drawing at the far right edge of the screen.
What is going on here?
No it does not adapt the screen it's standard 320 for the iphone. It actually adapts the simulator to the mac screen makes it bigger. And about the ball 320 is from left to right 0---320, and the 460 is from up to down 0----460. sow putting the ball at 320,100 should place it in the fa right.

Easy way of exporting #2x images for retina display?

I am creating a lot of webviews that must be compatible with both the iPhone 4 retina display and pre-iPhone 4 devices. It's painstaking to export multiple files for each image.
Is there a script or utility to automate this process?
If you're using Photoshop to process your artwork you just need to record an action while resizing an image to 50% of its original width and height. Using the image processor (Files > Scripts > Image Processor) you can then run the action on all images stored in a folder you specify. The images will be stored to a new location, so renaming them is easy.
Keep in mind however that resizing images (even if the new resolution is smaller than the old one) may render sharp and graphic content blurry sometimes. If your artwork is mostly graphical in nature and has been created in Adobe Illustrator (or a similar application) you should export the different resolutions right there.
Also keep in mind that the larger resolution images should be easy to resize to half the original width and height - you should be able do divide both values by two.
Imagine an image of 13 x 13 pixels (at #2x resolution), which will be scaled down to 6 x 6 or 7 x 7 pixels. You design your interface using the smaller size. For displaying the high resolution image, the iPhone will double the smaller images bounds, which would result in 12 x 12 or 14 x 14 pixels. The #2x image wouldn't fit precisely anymore - so there's either clipping, glitches at the edges or the image is slightly blurred because it needs to be stretched or pinched to fit in.
Finally, if you don't use Photoshop, here's two freeware tools that allow batch resizing of images too:
Fotosizer
Irfanview