Develop 2D game Inside Canvas Scaler
Asked Answered
B

2

9

I'm new in Unity and i've realized that it's difficult do a multi resolution 2d game on unity without paid 3rd plugins available on Asset Store.

I've made some tests and i'm able to do multi resolution support in this way:

1- Put everything from UI (buttons etc) inside a Canvas object in Render Mode Screen Space - Overlay with 16:9 reference resolution and fixed width.

2- Put the rest of the game objects inside a Game Object called GameManager with the Canvas Scaler component in Render Mode Screen Space - Camera with 16:9 reference resolution, fixed width and the Main Camera attached. After that, all game objects like player, platforms etc inside GameManager need to have a RectTransform component, CanvasRenderer component and Image Component for example.

Can i continue developing the game in that way, or this is a wrong way to do the things?

Regards

Bunder answered 11/8, 2015 at 15:3 Comment(4)
The Canvas is for GUI components and not made for creating a full game. However changing the resolution of the game should be fine, I'm sure you can set the viewport to stay at 800 by 600, I may have some coding laying around, but I will have to check later for youScissors
Thank u for your help. I'm waiting for your code to change the resolution of the game.Bunder
It seems the code I have laying around would help you here :( the code I have is basically keep the game resolution the same no matter what, even if they go fullscreen. however I did find this gamedev.stackexchange.com/questions/79546/…Scissors
Thanks, i will try this :)Bunder
G
5

Also don't forget GUI, Graphics. It's a common misconception that GUI it's depreciated and slow. No it's not. The GameObject helpers for GUI were bad and are depreciated, but the API for putting in OnGUI works great when all you need is to draw a texture or some text on a screen. They're called legacy, but there are no plans as to remove them, as the whole Unity UI is made out of it anyway.

I have made a few games just on these, using Unity as a very overengineered multiplatform API for draw quad.

There is also GL if you want something more.

Just remember - there will be no built-in physics, particle effects, path finding or anything - just a simple way to draw stuff on the screen. You will have total control over what will be drawn - and this is both a good and bad thing, depending on what you want to do.

Grillo answered 25/9, 2015 at 12:16 Comment(1)
As for multi resoulution - this is one of the things you will have to implement yourself - just as everyone did in old style frameworks like SDL, Allegro or those many flash engines.Grillo
C
2

I will not recommend you using Canvas Scaler for developing a complete game. Intended purpose of the canvas scaler was to create menus and you should use it to create menus only.

The 2D games created without the canvas scaler don't create much problems (mostly they don't cause any problems) on multiple resolutions.

So, your step 1 is correct but for step 2 you don't need to have a canvas scaler component attached.

Do remember to mark your scene as 2D (not necessary) and your camera to orthographic (necessary) while developing 2D games.

Craving answered 19/8, 2015 at 11:10 Comment(4)
Thanks for your help. What's the main problems that using canvas scaler for developing the complete game can cause?Bunder
Developing a small game with not so supper features: canvas scaler won't cause any problem, but in certain scenarios like you want the player to be able to scroll you map around by just dragging a finger on the screen. this may be a little tough (not impossible) as canvas scaler places limits on certain objects to be moved around at runtime. By 'not impossible' I mean that unity has made it available that you can inherit from their UI classes and extend them in the way you want.Craving
Thanks for your answer. Are u saying that i can have performance problems with that solution?Bunder
No It won't cause any performance issues. What I am saying it the it might make some feature implementations difficult for you.Craving

© 2022 - 2024 — McMap. All rights reserved.