• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Can you create a camera that goes outside the view?

L

Ledii

Guest
Hey, I'm creating a random generated map, and I would like to know the best way of doing cameras.
My current best option is making everything else besides the player move so that the player may rest in the center of the screen as I move off the room essensially.

Or are there better ways to use the cameras outside of the room bounderies?
 
I

icuurd12b42

Guest
remove the view follow from the view properties and set view_xview and view_yview yourself via code
 
  • Like
Reactions: spe

Perseus

Not Medusa
Forum Staff
Moderator
@icuurd12b42: Can you still use view_xview and view_yview in GMS 2? They are now obsolete I believe. They're no longer documented and camera_set_view_pos() appears to be the only way to change view position.
 
I

icuurd12b42

Guest
I have not looked at gms2's view system. but probably you need to hook a Camera for it yeah
 

mMcFab

Member
To be clear, yes, the view can still go out of room bounds but you will need to use the new camera functions - e.g., camera_set_view_pos instead of making the view follow an object.

If you need an overview on how to use all that stuff I have a link to a guide in my signature that may help!
 
L

Ledii

Guest
Thanks for the awsome tips!
I think I'll manage to pull something off with this info!
 

Xerohe

Member
For posterity, here's what I got to work:

Step Event (obj_camera, obj_game, obj_player, whatever):

GML:
    preferredHeight = 320;
    viewRatio = window_get_width()/window_get_height();
    calculatedWidth = preferredHeight*viewRatio;

    camera_set_view_pos(view_camera[0],obj_player.x-calculatedWidth/2,obj_player.y-preferredHeight/2);
    camera_set_view_size(view_camera[0], floor(calculatedWidth), floor(preferredHeight));
Then in Game Options, in Windows >> Graphics (may be different on other OSs idrk):

Allow fullscreen switching,
Allow window resize,
Scaling: Full scale

And finally, in the room you are using:

Enable viewports
Viewport 0: Make sure object following is turned OFF. The code above follows obj_player programmatically. The view will NOT follow an object outside of the room if this setting is enabled. I don't think your camera/viewport properties matter.

This will give you a view that maintains default aspect ratio (1:1) when the window resizes and follows the player outside of the room.

Obviously you can change the preferredHeight to whatever suits your game. You can also prefer a standard width instead if you want the view to expand/contract vertically instead of horizontally when the window is resized. To do this, just set a preferredWidth instead of preferredHeight and calculate the height by dividing the preferredWidth by the viewRatio.

EDIT:

You also need to set viewport 0 to visible in addition to enabling viewports in the room, or include this line of code in your step event:

GML:
    view_set_visible(view_camera[0],true);
 
Last edited:
Top