Question - Code SOLVED - Where should I make changes to a viewport

Discussion in 'GameMaker Studio 2 Community Tech Support' started by KingSolomon, Nov 9, 2018.

  1. KingSolomon

    KingSolomon Member

    Sep 17, 2018
    I am making a 2D platformer, I am using tile map collisions for all my solid objects (floors, platforms, etc...).
    I want my player to be able to go off screen when entering a doorway to a new room, and only when the player is fully off screen will they go to the new room.
    A tile map registers anything out of the room bounds as being a tile, so when I try to enter a doorway to a new room, the game stops me as if i have hit a wall because I would be going out of the room bounds.

    MY GOAL:
    To fix this I decided to create all my rooms to have an area of padding around to edges, and this padded area would be off limits to the camera, so the camera would stop following the character if it reached this padding boundary. I don't want the player to be able to see the padding, i just want the player-character to be able to enter it.

    This brings me to my latest issue: I have code that appears to correctly clamp the view ports x and y position so that it never shows the padding area. the debugging below it shows that the x and y positions are in positions I want, and that I am getting the correct camera from the correct view. But the view I see on screen when running it is still off and clamping to edge of the room instead of the padding area.

    I have tried moving this code into the Draw, Begin Draw, and End Step Events of the player character, and I have tried turning it into a script (what you see below is the exact script I used). and I tried to put that into the camera code using the camera_set_begin_script() function. I am not familiar with using scripts in game maker so I may have done that wrong.

    None of these solutions seems to have had any effect. I believe the problems is that the view is getting set by the room editor to follow the player character, then the view is getting drawn, then I change the view with my code, THEN the room editor starts over and changes it back before it updates again, undoing what i just did.

    Is there somewhere specific I can put this code to make it actually effect the viewport draw? or do I need to do things differently...

    cameraID = view_get_camera(0)
    camera_set_view_pos (cameraID,
                        clamp (camera_get_view_x (cameraID), paddingLeft,
                            room_width - camera_get_view_width(cameraID) - paddingRight),
                        clamp (camera_get_view_y (cameraID), paddingTop,
                            room_height - camera_get_view_height (cameraID) - paddingBottom))
    I Fixed this issue by setting the object following variable to none, and using this code in the Begin Draw Event of my playerChar.
    Last edited: Nov 13, 2018

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice