Setting a viewport

Hi all. I’m very new to Defold, but am liking what I see so far! I had previously been using GameMakerStudio 2, which I also really like (and has been growing impressively in recent years) but the jankiness of the UI and lack of a standard programming language got to me in the end. Prior to that I was hand rolling C++/asm.

I’ve been looking at the camera and rendering related documentation, but I’m slightly struggling to find what I need. I’m trying out a 2D pixel style game, and have set up nearest neighbour filtering, camera zoom and all of that, but I’m still finding it hard to get the viewport right.

What I really want is something like the GMS “viewports” feature. Where you can define a rectangle that a camera will focus on. I typically set the viewport to match the overall window size to get the desired effect (optionally with object following, which I see Defold also supports).

Is there a way to say, either via the camera or default render script, “display/focus on this rectangle” in world coords (or any other coord system)?

After spending more time looking into this, I’ve worked out that britzl’s camera script seems to be a great choice. I hadn’t realised how easy it is to add dependencies to Defold projects either (via the project settings). Using the FIXED_ZOOM projection and messing with the properties exposed by the camera script (the fact scripts can expose properties was also news to me) I’m getting very close to my desired result :slight_smile:

2 Likes