I'm working on a basic game with 3 scenes. The first is the menu (landscaped). From that I choose from sprites between two versions of the game: first is with only portrait (and upside down) orientations, and the other is landscape left or right. In ViewController I use viewWillLayoutSubviews. (I don't know if it's relevant now).
Is it possible to allow only portrait or landscape orientation for different scenes?
Related
I have a game that I’m porting from iOS to MacOS. On iOS, everything functions as it should on retina and non-retina devices. On Mac, it’s a different story.
I have two class properties: upperCameraPos and lowerCameraPos
The game is in a window and the scene is twice the height of this window’s content view (SKView). When the game starts. the camera node is positioned at lowerCameraPos, revealing the bottom half of the scene. When a button is pressed, SKAction’s moveToPoint: method is used to scroll the scene up, revealing the top half. On retina and 4K Macs, this works as expected.
However, on non-retina Macs (tested on late ’07 iMac & late ’08 MacBook), the same code for setting the camera’s initial position does not reveal the lower half of the scene, but rather shows the middle of the scene (which is the camera's default position).
I’ve done a considerable amount of searching and haven’t found any explanation for this. Does anyone know if there are any issues between retina & non-retina when positioning a camera node in a scene on Mac?
I figured out what I was doing wrong. I had the scene's scale mode set to SKSceneScaleModeAspectFill. After changing the scale mode to SKSceneScaleModeResizeFill, the camera node now scales to the correct parts of the scene regardless of whether the screen is retina or non-retina.
I'm going to show you an image that contains my first UIViewController presented in Interface Builder (using the 600x600 Any/Any View).
MainViewController
For now, just look at the UIButton with the C label and the Play button. I added Align center x to: horizontal constraints to both. When I preview what I have (forgetting about the other views and buttons you see), the 2 buttons are centered properly. However, when I switch different device sizes, they do not change size...which makes sense.
What I want is for a way to make those 2 buttons stay proportionally circular and centered on the superview, but adapt their size and Y-position depending on the device size. What constraints would I need to attach in order for that to work? I don't want the buttons to be stuck in the spots you see in the image, I want them to adapt to the device size.
To talk about this further. The game 'Color Switch' does not appear to use constraints in terms of having any view/image/button/label constrained to a certain y or x position. Going from a 5c to a 6s, it's like looking at a blown up version of the game. The buttons and title label at the top are not constrained to the same y position on each device.
You could create constraints to center the buttons to the top-level view and then make their width proportional to the view width. Then on a larger screen, the buttons will be larger and on a smaller screen, they will be smaller.
I made a game. I want to use it on iPhone and iPad(Universal game). I set screen 640x1136 in gamescene.sks file. When I play the game on all of iPhone, screen is seems perfect. But when I play on iPad, game screen looks bigger than iPad screen. How can I set screen for iPad?
It all comes down to the scaleMode you are using.
You have 4 options
This first 1 resizes your scene frame, the others keep the scene at the size you specified and scale to fit the screen.
.Resize, as stated, resizes your scene to fit your screen. If your initial scene is 10,10, it will make the scene size 320x480 on an iPhone 4s
.Fill (Default), which keeps the coordinates of your scene the same, but stretches in the x and y direction. If your game was in Landscape, and you design for a 4:3 screen, you will create a fat effect when going to 16x9
.AspectFill, which keeps the aspect ratio the same, but will scale your scene till the furthest borders are hit. If you are in landscape with a 4:3 scene, it will stretch to the left and right borders, making the top and bottom cropped to maintain the ratio.
.AspectFit, which keeps the aspect ratio the same, but will scale your scene till the nearest borders are hit. If you are in landscape with a 4:3 scene, it will stretch to the top and bottom borders, making black borders appear on left and right.
If you want your game to appear the same size on all screens, your best bet is to use .AspectFill, and plan your game around the cropping. (Basically do not put anything important in an area that gets cropped)
Is there a way by which the constraints I give in portrait orientation DO NOT apply in landscape orientation and vice versa.
I am working on an app which has a lot of small images and text fields on the screen.
I need to give different positions and coordinates when these are in Portrait and Landscape orientation.
With iOS8/Xcode6 there are Size Classes.
Here's all the magic:
With the same storyboard, you can set different constraints for different kind of device, with no code.
(Click to enlarge)
(source: noelshack.com)
(source: noelshack.com)
On the left, the regular layout. On the right, the layout when there's a compact width.
You can see that the bottom bar turns blue when you are in a specific size class, meaning you only make changes on that particular size class.
I want to display a bitmap on a WP7 in vertical position, but it rotates it 90 degrees and coordinates are in landscape position. Is it possible to make WP7 display everything in vertical mode and make coordinates starting from top left corner in vertical mode? If not, whats the best way to display my bitmaps in vertical mode? Should I rotate my bitmaps when I design them, or should i use rotation in my drawing functions? I use XNA spriteBatch.Draw to draw my bitmaps, but it has some advanced rotation techniques that I don't understand.
XNA apps are based on the assumption that the game will be displayed in landscape mode. Whether it's easier/better for you to rotate things at design time or when displayign them in the app will depend on various factors, including: what the game does; your preferences; the number of items; the impact on movement calculations; etc...