Reputation: 13
I have been playing around with unity for quite some time now, and I have an app or two published on android, but I have yet to figure out one really important thing that keeps eluding me about mobile.
I have looked at various tutorials on things such as unity2d physics and things of that nature, and I have seen tutorials where the person puts a ground sprite on the ground, then attached an edge collider to one side and so on.
Now, I may be wrong about this, but to me it seems like if you are making any game at all that involves having to set any sort of boundaries, or objects that you collide with inside a set play area, you can pretty much never use the editor for any sort of level design, and everything has to be done by script because every object you create has to have its location and size set by script on startup to account for various screen sizes.
Am i wrong in this? Is there indeed an easy way to create a level using the editor to import sprites and create shapes and edges and object and then have the game automatically scale and move the objects to the proper limits based on screen size?
For me, every time I have done an android game or any mobile game in general. I have had to generate all the objects via script, add components via script and generally do everything via script to the point where my actual editor pretty much just had the camera object and a script attached to it and thats about it.
Is there an easier way? because so far all the tutorials about 2d games I have seen are pretty much useless for mobile because they use the editor to add sprites and edge colliders manually, which to me seems like it would not look right 90 percent of the time.
Any thoughts would be appreciated.
Upvotes: 1
Views: 305
Reputation: 12590
Yes, this is unfortunately an absolute basic aspect of game design in our era.
It is indeed very, very difficult to make 2D games work on all different screen shapes.
Consider say some sort of landscape 2D arcade game - perhaps where you shoot against each other. What does it actually mean if two people are competing, and one has a 4:3 screen and one has a 16:9 screen?
Should it actually take longer for one user to fly across the screen?!? Should you adjust the speed of the ship, so that screen-travel-time is constant?!?
Should you just show more stuff on the edges? But wait - does that mean some players get far more warning of arriving enemy or scenery??!
Nobody has the answer - it is very, very difficult.
it is difficult conceptually, and a real pain to program.
In answer to your question, there is absolutely NO built-in method to deal with these hassles in Unity (or any game engine).
Almost all teams have code like this .......
/*
Call this dynamically, probably from SizeCare or RotationCare
Position something in relation to the dynamic screen edges
- reactively so to speak
This is critical for (for example) knowing where to launch sprites from,
knowing where to dispose of them, and so on.
*/
using UnityEngine;
using System.Collections;
public class KeepAtScreenEdges:MonoBehaviour
{
[Header("Left and right...")]
public bool keepOnLeftEdge;
public bool keepOnRightEdge;
[Header("Bottom and top...")]
public bool keepOnBottomEdge;
public bool keepOnTopEdge;
public void ScreenMaybeChanged()
{
if (keepOnLeftEdge) gameObject.ScreenLeft();
if (keepOnRightEdge) gameObject.ScreenRight();
if (keepOnBottomEdge) gameObject.ScreenBottom();
if (keepOnTopEdge) gameObject.ScreenTop();
}
}
you just stick it on a marker (marker: empty GameObject)
there's the "top left" one ...
and indeed you'll have whole constellations of "reactive markers" like this.
Then, every single thing you do in the game, is positioned in relation to these.
So for example you'll have a marker for "place where offscreen enemies come in to existence, just off the right edge of the screen". And you'll use that extensively for launching enemies, or whatever.
You can do nothing in the editor: everything is reactive. (Well, indeed, you have to program editor code so that it too is perfectly reactive, for during development: you
Note that - thank goodness - Unity's awesome .UI system of course is reactive, and that, thank goodness, takes care of the UI aspect of "modern frickin' reactive game layout". (Then again, it's not really that easy to be absolutely expert with .UI, and you have to be. And that's absolutely trivial compared to "game layout reactiveness" :/ )
Again - just fundamentally - forget about executing it technically! - are you going to go for a solution like "equal speed across the screen" or "always show more trees at the top" - or whatever? It's very difficult.
Upvotes: 1