Where did these borders come from in Monogame Android? - monogame

Even when I use GraphicsDevice.ToggleFullScreen() or GraphicsDevice.IsFullScreen = true; followed by GraphicsDevice.ApplyChanges() as described in this post, I still seem to have this border on both edges of the screen, shown in classic CornflowerBlue for contrast in this screenshot. The background image is anchored at 0,0 with width and height set to the dimensions of the screen. The "borders" seem to be about 10 or 20px from what I can guess, and not at the top or bottom, only at the left and right edges. I can't understand where this is coming from.

If you want your game to be at full screen of every device:
#if ANDROID
graphics.IsFullScreen = true;
graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
graphics.SupportedOrientations = DisplayOrientation.Portrait;//if your game does NOT support for anything else but portrait mode
graphics.ApplyChanges();
#endif
However, in this case, you need to be careful because the ratio of devices are different, some are 16:9, some are 4:3, etc. If you need your game to be adapt to all of them, you better adjust the sizes of your game objects to be changeable or set them to be proportional.

Related

Responsive in Unity 2D

I want my Unity 2d game responsive in all android mobile device. So i anchor 4 canvas to 4 edge (top left, top right, bottom left, bottom right).
But when i change a device, the size of each component is not change. Now i want the size of each component change depend on each resolution of device. What should i do or what tutorial i can follow.
Problem will come when i get small screensize, it like this
Canvas Scaler
You can solve it using Canvas Scaler.
You can find various options in the list in UI Scale Mode.
When selecting the option to fit the commonly used screen size,
If you want to align UI elements to the height, set Match, an element of Screen Math Mode, to Height, and if you want both height and width to match, place it in the center.

Setting X of camera's viewport causes the black strip to be rendered

I’ve run out of ideas, please help me.
That's the situation:
Imagine a simple object in the center of screen (it's always so, because camera has an orbit script)
Then we add a canvas image, 300px width, for example, on the right side of the screen (blue one in the picture). Our cube is not centered anymore.
For example, we can change X property of camera viewport rect, but we'll get a black strip and if object appears in this zone, it would not be rendered.
So, what can I do to offset camera position?
Thank you in advance!
The best option I have for now is:
create basic UI for FullHD resolution and make right panel as wide as black strip is
if user's screen bigger than 1920px, than change Canvas Scaler mode from Constant pixel size to Scale with screen size

UnityVR - Having the both renders display the exact same image for each eye

When Unity builds a VR project, by default it is set to make the two views stereoscopic. It slightly offsets the camera position of one eye to give the user a sense of depth.
For example a square will appear slightly to the left on the right view compared to the left view.
I want to make the camera truly monoscopic by removing the offset that is created when i build the project. Each camera should render all objects in exactly the same position for both eyes.
One of things i tried was creating two camera and setting them to the left and right eye. Then i manually set the position/rotation of one camera until it looked monoscopic
It worked fine on my pixel phone, but as soon as i put the project on my test phone i noticed that the difference in resolutions messed up the view i was going for. The blocks were not in the same position when i looked at both renders.
If anyone has any solutions or ideas as to how i can go about this, i would greatly appreciate it.
Thank you!
You can still use 2 cameras, but instead of offsetting them, you can just make the width of the camera half.
Make 2 cameras, set their positions to exactly the same.
On the left eye camera, set the width to 0.5 and the x position to 0.
On the right eye camera, set the width to 0.5 and the x position to 0.5.
You should now have 2 cameras rendering the exact same thing, but twice across the screen, with no sense of depth.

Canvas too big for the camera in Unity

I have created a 2D game with an orthogonal camera and using 16:9 display size.
I dragged my background image onto the hierarchy (it's about 2048x1152) and then set the camera size to be 22.5, which made it fit the background perfectly and displays just right.
However, when I add a Canvas for a UI it is absolutely giant, about 100 times bigger. It only becomes 'normal' size with respect everything else added when I set the camera to its default size of 5. So when I add a small graphic, it too becomes giant.
I'm simply following a book I read and I'm not doing anything to deviate.
Am I doing something wrong? Below is what I mean. The background image is the little image in the bottom right and the outlined rectangle is the canvas with a small graphic added.
Thanks.
To force your Hierarchy Canvas UI to the same resolution as the Camera View in your Unity Editor Scene window resolution (i.e. not ridiculously massive), or in other words get the Canvas to fit into the Camera size in the Scene, do the following:
Set the Canvas component's Render Mode to Screen Space - Camera.
Make sure you select or drag the relevant Camera from the Hierarchy to the Render Camera field in the Inspector.
You should use the Unity canvas for this along with the canvas scaler component. If I'm not mistaken it will scale all elements relative to the screen they are viewed on.
The canvas scaler allows you to match the scaling based on a preferred viewport size which is a life saver.
However this may not fit you needs perfectly as it would mean that the background element would become fixed. So if you wanted to pan the element you would need to move it's x and y elements within the canvas.
Hope that helps?

Lower Left Coordinates of SKScene

I'm new to Swift SpriteKit programming and the coordinate system is driving me crazy. I create a sprite and I want to move it to the four corners of the screen. So, I set the position to (0,0). That's off the bottom left corner of the screen. Through some manual testing I've developed the chart below. The lower left and upper right are what the iOS simulator report when I touch the screen.
I have 2 questions:
1: Is there a method of determining the coordinates of the lower left hand corner of the view? Maybe I could build a dictionary with the coordinate values and the determine the machine type and then set the offsets. But, that's a lot of work and might not be accurate for new devices. It just seems that there should be a scene or frame property that I can use to put an object at the bottom left of the window.
2: The math doesn't work. In the iPhone5, 300 (lower left x) + 320 (width) = 620, not the reported 727. Same issue is true with the y coordinates. How does this work?
I set as few parameters as possible. I have not changed the anchorPoint or position of the scene.
Device Size LL UR
iPhone4s (320,480) (260,0) (766,764)
iPhone5 (320,568) (300,0) (727,764)
iPhone5s (320,568) (298,0) (727,764)
iPhone6 (375,667) (297,1) (728,765)
iPhone6plus (414,736) (298,0) (728,766)
iPad2 (768,1024) (226,0) (800,768)
iPad Air (768,1024) (224,0) (800,767)
iPad Retina (768,1024) (225,0) (800,768)
Ok, I think I figured this out. Setting scene!.scaleMode=SKSceneScaleMode.ResizeFill allow me to identify the four corners of the screen. So, now I can determine when a sprite crosses the edge of the screen. This doesn't seem to distort my images. I haven't been able to test it on a read device yet, but it leaves a blank area around the iPad2.
Applause for the hard work! haha
If I was going about getting values for the lower coordinates, I would use CGRectGetMinX to get the x-coordinate and CGRectGetMinY to get the the y-coordinate likewise:
CGPoint minimum = CGPointMake(CGRectGetMinX(self.frame),CGRectGetMinY(self.frame));
Then, if you wanted to get the top coordinates just use the same things but say MaxX or MaxY. Yeah, the coordinates are a bit confusing but if you use those then it will be a breeze.
EDIT: If you need to find if a body has exited outside visible space, so far what has worked for me is making a physics body to detect contact with it on the edge
[SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]
possibly another option you could try is to see the bounds of a UIScreen object.