1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

GMS 2 Room Viewport Scaling Issues

Discussion in 'Programming' started by Will Roberts, Feb 15, 2020.

  1. Will Roberts

    Will Roberts Member

    Joined:
    Feb 14, 2020
    Posts:
    11
    I am creating a new room and setting the viewport, but when I go to that room, everything is stretched and looks off. How do I get the room settings/viewport settings to mirror properly?

    Here is the code:

    new_room = room_add();

    room_set_width(new_room,floor_width);
    room_set_height(new_room,floor_height);
    room_instance_add(new_room,0,0,o_draw);
    room_set_viewport(new_room,0,true,o_player.x,o_player.y, 400, 240);
    The first room I have has the following settings (which has a good display without things being stretched). Of note, when I go back to the first room in-game, the viewport settings are good.

    Here are the first room settings (which are set in GMS2's Room Editor Properties Tab):

    Room Settings:
    Width: 900
    Height: 400

    Viewports and Cameras:
    Enable Viewports (ON)

    Viewport 0
    Visible (ON)
    Camera Properties:
    X Pos: 0
    Y Pos: 0
    Width: 400
    Height: 240
    Viewport Properties:
    X Pos: 0
    Y Pos: 0
    Width: 1280
    Height: 720

    As I create more rooms, I'd like these settings to be replicated across the rooms.

    Thanks, and any help is appreciated.

    Will

     
  2. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    2,102
  3. Will Roberts

    Will Roberts Member

    Joined:
    Feb 14, 2020
    Posts:
    11
    NightFrost,

    Awesome tutorial, and yes, it does help out with following his first set of rules (which is don't ever set properties within the room editor and don't use anything with the word port).

    So, changing to his camera instead of mine and setting everything up via obj_camera like in his video leaves me with similar issues;

    when I create a room with the following code now, (and camera being persistent)

    new_room = room_add();

    room_set_width(new_room,floor_width);
    room_set_height(new_room,floor_height);
    room_instance_add(new_room,0,0,o_draw);
    When I navigate into the next room that is created with the above code, the camera isn't keeping the zoom settings and everything looks really tiny. but when I go back into the first room, everything is fine.

    I'm overlooking something simple, because when I create a room in the Resources tab, everything works fine, things get weird when I create a room with the code above.

    Thanks again, and any help is appreciated.

    Will
     
  4. Will Roberts

    Will Roberts Member

    Joined:
    Feb 14, 2020
    Posts:
    11
    Okay, so this might be a completely different issue that is related in some way, but I have found that if you create a room while the game is running, there seems to be a new camera applied that overrides my o_camera (even though o_camera persistent).

    So, my question is; how do you create a room while the game is running and continue to use o_camera?

    I've followed PixelatedPope's video (from above) and created his camera following his guide perfectly. The camera is persistent and the settings retain when going between rooms that have been created in the resource tab prior to running.

    If I run the game and then create a room with code (like below), then o_camera doesn't seem to follow into the new room).

    If I create a room:

    global.game_rooms[room_counter] = room_add();

    room_set_width(global.game_rooms[room_counter], rm_width);
    room_set_height(global.game_rooms[room_counter], rm_height);

    room_counter += 1;

    (I use a counter to help cycle the the rooms.)

    As soon as I leave room0 and go into one of the generated rooms, the camera properties change to something else. They remain this way until I return to room0 and then o_camera settings are applied again.

    Thanks again.

    Will
     
  5. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    2,102
    Sounds curious. I would have assumed that everything camera-related would inherit to all rooms, but maybe it isn't so. I've never had to use programmatically created rooms myself so I've no experience in their pitfalls. If you can't solve the issue, perhaps try using a pregenerated empty room instead? In either case (pregenerated vs programmatically created) you have to fill them with all the necessary stuff anyway. Since rooms will, upon exit, lose all content not set in room editor, you can keep reusing the empy room again and again (persistence creates exceptions of course).
     
  6. Will Roberts

    Will Roberts Member

    Joined:
    Feb 14, 2020
    Posts:
    11
    NightFrost,

    So, when you create rooms with code, apparently the default camera isn't included. All you have to do is create a default camera.

    view_camera[0]=camera_create();

    Thanks for the help. You pointed me to PixelatedPope, and he was the one that figured this one out.

    Will
     

Share This Page