• 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!

Wrapping my head around Views

Xer0botXer0

Senpai
Hi fellow game devs,

Hope you're all doing great!

So I'm currently adding views into my game, or rather one view. Just to paint a picture, and I've been having bugs for days with them.

So three things, (1)what I've already done, (2)what I'm trying to do, (3)and then some questions in regards to views!

(1)
once the game opens the menu is available, I've added window_set_fullscreen to the options, this works fine nothing to it. Then the player starts a new game and I've set up a view[0] in the room editor, I've also done this in the creation code but the room editor does justice,

I've setup the view_x/yport[0] and view_x/yview[0], I've also set the height/width of both of these, the port being the size of the game room, and the view x1200 y800, I've also enabled that option in game maker to smooth pixels or something like that, it makes things look so much better in fullscreen mode.

Think of an RTS game where you're top down and you can move the view around the map by dragging your mouse against the boarders of the screen, when the mouse is within range of a boarder the view_x/yview[0] increases respectively based on which direction is wanted. this works.

Right so another thing in RTS games is zooming, getting a bigger picture or zooming in for curiosity.
I have code for zooming where it increases the view_h/wview[0] by x amount of pixels per zoom in/out. this works fine too

I've also created limits as to not zoom in too close or zooming out too far, same with directions I've prevented moving out of the room area.


(2)
Now here's the trouble!
My first problem was that my GUI panel and all its content needs to remain within the view when Im moving around. I did that by creating a master gui panel object, where all the content links to that objects x/y coordinates, and from there that master objects coordinates get incremented/decremented when the view is moved retaining the panel and content in view.

Right, now when it came to zooming in and out, that same method didn't work,
I have no idea how to keep these objects within a view, while preventing them from growing/shrinking when I zoom in and out, the way I zoomed was by increasing the x/y position of the master GUI panel object when the view_w/hview[0] was increased. I increased/decreased it by 25 pixels per a scroll, both the view and the object, so the view zooms in and out correctly but the object doesn't move accordingly. It also grows/shrinks


here's a sample idea for how I'm handling zooming

when the player scrolls in/out, the view_hview[0] & view_wview[0] is inc/dec by 25.
In the same code block the master gui panel object x/y pos gets inc/dec by 25

The master object is at view_wview[0]/2 and height view_hview[0] - 200.
So basically it's at the center/bottom of the screen(view), the master objects origin is centered too.

When I zoom out, I want the master object to increase by 25 on the x axis, keeping it centered..
and increase by 25 on the y axis, keeping it at the bottom.

but instead it moves diagonally way out of position
it also inc/dec in scale..

Okay so since then I disabled views until I understand it better(with the help of the community!) and I just tried to get things going because I mean, I cant work on other things in the game is the view wont even work.


(3)


While typing this up I figured I could counteract the inc/dec in master(+ child) scales by actually setting the scale of the sprite_index. (bug while zooming)

If I scale a sprite, and have precise collision checking on, will the collision checking inc/dec to encompass the new size ? (possible solution)


I had to draw text on an object, I was recommended to use draw gui event(cant remember why) which I used to draw the text at the x/y position of the object, this object is following the master panel object correctly.
The text on the other hand does not draw at the objects x/y position! Im not sure why, it draws at some random location :/ I think I switched to the normal draw event and it actually drew where it was suppose to.

Any idea why this is ?
From what I understand draw GUI ignores views, where the normal draw event doesnt, so how does that translate into reading the x/y coordinates differently ?


Is there a way to make the view/port smaller than the game window, leaving say a rectangle open so I can put gui in there, I mean why create gui over the game screen when you wont be able to see it ?


Okay beyond all that, are there any issues that I should try to work out before moving too far ingame regarding views, if possible I'd like to deploy onto android later on, is the setup for that simple or do I need to take things into account now already ?


And thank you for having a read here, if possible please have a look and see if you can explain the issues a bit. I literally spent the entire weekend trying to implement views properly but Im lacking some information that's causing it to be buggy.
 

TheouAegis

Member
The GUI is allllmost the same as the view, but without regard to the room. So (0,0) in the GUI is the same as (view_xview,view_yview) when you have only one view visible. However, (x,y) in terms of object positions are relative to the room, not the view. So drawing something in the GUI events at (x,y) is the same as (view_xview+x, view_yview+y) which is obviously not what you want.
 
Top