• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Simple Viewport Setup- Can I Toggle Tall and Wide?

K

KingRegicon

Guest
Hello, everyone!

I have been practicing GML for a few weeks now, and I'm really loving the problem-solving aspect of programming. The manual, online tutorials and GML forum posts have helped me through every problem I've faced so far, but now I must write my own post in desperation.

The Setup:
Two big "boxes" of stuff, sometimes drawn on top of each other (tall) and sometimes drawn next to each other (wide.)

The Dream:
I would like the game window itself to resize and fit both of these boxes perfectly- sometimes stacked vertically, sometimes situated horizontally, side by side.
I would like to be able to change my viewport / camera / etc. to toggle between these modes, all in code.

What is Working:
I have a boolean variable: "v_orient."
For debug purposes, I can currently toggle this on/off with my "Y" key.
If true, the game window sets its height and width to fit both boxes "vertically_oriented," as top and bottom.
If false, the game window sets its height and width to accommodate them horizontally, side by side.

What is NOT Working:
The way I've made the most progress so far is by changing the Properties *manually* in the room editor. (This is not ideal, of course.)
If I set viewport 0 to be tall, it won't display the horizontal configuration correctly- and vice-versa, if I set it to be wide.

Illustration_00.png

The Code: (everything else was commented out, so I could see which parts are even having an effect.)

(STEP EVENT)
Some_code_02.PNG
Some_code_00.PNG
^^^ written in a script that runs on the "step" event, on a game object that persists across rooms.

(CREATE EVENT)
Some_code_01.PNG
^^^ written in a script that runs on the "create" event, on a game object that persists across rooms.

I've commented out all of my code- except the lines above- to see which lines were having an effect at all. (I tried a lot of tutorials.) Disappointingly, almost none of them did. I am now forced to admit that I have *no idea* what is required for a working viewport setup- the variables, functions, cameras, etc.

If anyone could help me understand which parts of the system I need to implement, I would appreciate it!

Thanks!
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
^^^ written in a script that runs on the "create" event, on a game object that persists across rooms.
Views are per-room, so that object will only have any effect in the first room. Change the views in the Room Start event instead, that runs every time the object is present when loading a room (Create is only run when it's first created).
 
K

KingRegicon

Guest
Views are per-room, so that object will only have any effect in the first room. Change the views in the Room Start event instead, that runs every time the object is present when loading a room (Create is only run when it's first created).
Thank you, this is the kind of info I'll need to get me pointed in the right direction!

I originally had these in a Room Start event, actually. I was getting turned around bouncing back and forth between events to adjust things, and eventually consolidated all code pertaining to the viewport to a single Step event, where I could experiment more clearly and consistently. I moved only those two lines out again, because calling them on Step created hundreds of cameras very quickly. 😅 Moving them to the Create event was simply my mistake!

So, I've moved them to the Room Start event as you suggested, and it hasn't seemed to change anything yet. Pressing "Y" in the first and subsequent rooms yields the same results as illustrated above.

Are the cameras I'm creating and assigning to view_camera[0] and view_camera[1] automatically doing anything, or do I need to assign, activate, or initiate them somehow?
 
K

KingRegicon

Guest
UPDATE:
I found a solution! I downloaded PixelatedPope's camera example file, and found the answer there.
All I had to add was one line, calling the surface_resize() function.

Solution_00.PNG

Now it seems to work perfectly.
(Creating the cameras was unnecessary in my situation, so these lines here are all I've kept in.)

For anyone coming across this post in the future, I hope my code helps, but check out this forum post which ended up solving my problem:

His third video down had the file I downloaded to find the solution.

Thanks, @Yal for your reply!
Cheers!
 
Top