This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Lower Camera2Ds viewport?

RukiriRukiri Posts: 58Member

Love how simple Camera2D is to use, but I don't like that it's your projects width/height.
Is there a way to give it a custom viewport?

My resolution in game is 1920x1080 (easy to scale down) but would like to lower the cameras view to half if possible only because I'm working on a 2D game and I don't want the camera to see outside my scene (which is basically just a TileD map imported into Godot).

Thanks for the help :smile:

Best Answer

  • AvencherusAvencherus Posts: 49
    edited October 2016 Accepted Answer

    I don't think you're wanting to manipulate the viewport, that isn't going to achieve what sounds like scrolling. The way that's done is by putting a camera through another viewport, and having that viewport attached to a viewport sprite, that will render it's texture as what is seen in that secondary viewport. However, doing that is going to leave you with empty border regions, since the rest of the canvas will still be displayed.

    I'm guessing you're talking about clamping the camera to the edges of the map as you scroll through. The Camera2D provides clamping functionality through the Limit property. It gives you a Left, Right, Top, and Bottom edge. Set those to the margins of your level as it is on the canvas, and that should keep the camera inside the world.

Answers

  • PaulMurrayPaulMurray Posts: 26Member

    There's a zoom value, increase that and you'll see less of the scene, though it will make everything appear bigger.

  • AvencherusAvencherus Posts: 49Member
    edited October 2016 Accepted Answer

    I don't think you're wanting to manipulate the viewport, that isn't going to achieve what sounds like scrolling. The way that's done is by putting a camera through another viewport, and having that viewport attached to a viewport sprite, that will render it's texture as what is seen in that secondary viewport. However, doing that is going to leave you with empty border regions, since the rest of the canvas will still be displayed.

    I'm guessing you're talking about clamping the camera to the edges of the map as you scroll through. The Camera2D provides clamping functionality through the Limit property. It gives you a Left, Right, Top, and Bottom edge. Set those to the margins of your level as it is on the canvas, and that should keep the camera inside the world.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.