Pixel art across iOS resolutions - swift

In my iOS game, I have custom buttons in a pixel art style. There are a few buttons in a row at the bottom of the screen, and I want them to fill the screen width, regardless of iPhone resolution.
I have been trying to think of a way to achieve this. Is the best way to do this (and to target devices for all other assets, too) by just checking the resolution, e.g. with self.size.width, and then setting the image (so have multiple images for the buttons, to ensure pixel art style is correct and not distorted) and position for that particular device?
Is there an easier / built in way to do this?

Related

How to make responsible camera for multiplie resolutions?

I m working and some 2d game for mobile phones relate to chess, and I have a trouble with show board for different resolutions of mobile screens.
Here u can see how it must be on 9:16 resolution:
https://drive.google.com/open?id=1MFt-FtEtqkk7QWQC2oAtMBA0WAgOIV4h
And how it looks on smaller screen:
https://drive.google.com/open?id=11WLYZwHEa9ijXbekzUbE5ZbjbEnjZ6Lb
How can I protect my chess board from cropping?
Answer: it depends on how you want it to look.
If you just want it to fit perfectly horizontally, you need to perform 3 steps:
Evaluate the width of the Sprite (with Sprite.bounds)
Evaluate the width of the current screen (with Screen.width and using the main Camera)
Scale the Sprite to fit the screen
If you are using UI elements, you can do the same thing but you won't need to use Camera, just scaling according to the Screen width (look for RectTransform.deltaSize to give you the size of a UI element).
If you are using UI, also consider using layout groups, they help you with fitting the content to screen size.
Anyway, in a device with small width, maybe the table will get too small and you might have to think about better options to display the board instead of just scaling with screen width.

Auto Layout Swift 4 Xcode 9 For Multiple Devices - Am I doing it Wrong?

I am having severe difficulties finding a clear working world example of auto layout on multiple screen sizes. Most tutorials have basic stuff like a button thats centralised and then after adding constraints in Interface Builder it scales with the device. One button is simple but in my example for the iPhone 4:
There are quite a lot of labels / buttons and some that are not central. The above screen shot is exactly how I want it to look on all devices.
The app is for portrait only but I want to target all devices. I tried slowly adding constraints to items from the bottom up using a multiple of the superview to position and size items and then applying aspect ratio to UI Objects (got as far as the got it button but not the red arrow buttons) but as you can see in the next picture for the iPhone 8 plus... the white space isn't going to perfectly fill like in the iPhone 4 which will leave me with a big gap at the top.
Is there a way I can change just the iPhone 8 plus layout in Interface Builder to build a layout that caters for the extra screen size?
The iPhone 8, SE and X layouts are equally awkward with extra white space.
I tried size classes but that changes it for all phones.
Is there a way to centre what I have done so far?
How do you guys position objects in auto layout that are not centred?
Am I going about it the wrong way by applying X / Y constraints using a multiple of the superview? - same for the width. I'm only specifying widths as a multiple of the superviews width then adding aspect ratio.
I just need a real world working example I can learn the basics from or a system to create for multiple devices that I can follow. I don't want to use a 3rd party library.
I really hope someone can help point me in the right direction!
Krivvenz.

Loading levels from xml and supporting screen resolutions in Ios

I am developing a game that uses levels. The levels are made at a default scene width and height resolution.
The thing i am worried about is when the game is played on IPads iphone 5′s etc, the position of sprites loaded from the level xml files will be out of place due to the screen size.
In my case, could someone tell me the best thing to do in this situation or some advice on the approach i should take?
Also if any has experienced this, please let me know.
Thanks. :)
Generally this has nothing to do with how or where you store the level data.
These are the standard approaches, which one works for you depends on your requirements and desired results:
design each screen resolution individually (error-prone, tedious)
design for one screen resolution, then scale up or down according to screen aspect ratio (can lead to skewing as the screen size scaling for width & height are likely to be different)
design for the smallest screen resolution, then center the contents on the screen (this leaves unused areas either at the top/bottom or left/right sides)
same as above, but zoom content to fill the screen (this will remove the letterboxing, but also partially remove one side's content from the view)
In essence this is the same problem as movies have in trying to fit to screens of varying aspect ratios.
In general this is all a matter of scaling the input (positions) to a desirable output. The easiest approach is to maintain aspect ratio and allow for letterboxing. However Apple may reject letterboxing apps if nothing is done to hide the letterboxes (black areas) since Apple requires apps to support widescreen resolution, and letterboxing does not normally fall into their definition of "supporting widescreen".

how to make my game run on different devices with various resolutions?

I'm developing a game for 480*800 resolution screen,but now I want to run it on all other screens I tried to run on 7" screen but my background image and even sprite position are out of order.Can anyone please suggest me with some examples about how to make my game compatible with different screen resolutions.
I used the below code but that was of no use.I have seen somewhere that by using FillResolutionPolicy() along with the below code andengine sets automatically for different screens but I did not notice any change ,so please help me in solving it.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics)
CAMERA_WIDTH = metrics.widthPixels()
CAMERA_HEIGHT = metrics.heightPixels()
FillResolutionPolicy automatically scales everything depending on your screensize.
Camera camera = new Camera(0, 0, 480, 880);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new FillResolutionPolicy(), this.camera);
This is what I use, and if I start the game on a bigger device, everything is scaled automatically.
FillResolutionPolicy is probably exactly what you need.
(The code above might not be 100% accurate as I can´t access my actual code right now)
FillResolutionPolicy() is just for the black stripe you have either left/right or top/bottom depending on the screens aspect-ratio. see this post in the andengine forum to read about resolution policy.
the camera width/height has nothing to do with the devices real resolution, since it's projected to either the devices height or the devices width (depending on the aspect ratio of your camera settings & the aspect ratio of the device). there is only one point where the DisplayMetrics are useful - get the screens density/max resolution to load res-depending sprites (like: like higher density, load larger sprites) but that's not your problem atm.
the games i tested andengine with, are all resolution independent and can be run on 4, 7 or 10 inch displays with different resolutions without any addition/code changes.
i think it's more like a coding mistake where you added sprites and background image to the scene. for example, by recalculating CAMERA_WIDTH/_HEIGHT with metrics and sprite positions that depend on the CAMERA_WIDTH/_HEIGHT, you mix up the sprite positions with the devices resolution and everything looks a bit out of order. perhaps you add some code, and i can edit my answer pointing you in the right direction.

How to maintain text clarity of image while zooming?

I am developing an app for a magazine and simultaneously I am creating images for those magazines using photo shop.
But, when I zoom these images, the text quality is getting loosed.
I have referred to other iPad magazines like India Today. In that, even though I zoom to maximum extent, text quality is too good.
how is that possible? My each image size is almost 800 KB. Even then, when I zoom, I loose the clarity of image. How to maintain the quality of text even when I zoom?
Is that something to do with photoshop editing or coding?
We use the following table for our iPhone/iPad projects when the OS target is 3.2 or above.
Because you are using raster graphics you are in a losing battle of file size vs. zoom quality. Text is natively vector and scales beautifully as you zoom, so you are much better off rendering text as text rather than generating text as an image in Photoshop. There are many ways to accomplish this, one being to have the image be a background layer and the text be a UILabel above the image.