Clipping the game with non gui elements

#1

Is there a way to clip the view of a collection in order to see only a part of the world?
This is important when using the use_fixed_fit_projection render setting. This setting allow the game to stretch proportionnaly to the original game but if the window isn’t the same ratio as the game settings, it show more of the world. Thus, it can show parts of the game where I spawn object or destroy them.

As a solution, I used a single black tile as a tilesource then draw a tilemap masking everything except the screen on top of every other element in my game (z value of 1):
mask_screenshot

In Gui, it is possible to use clipping settings to mask part of children nodes. Is it possible to do the same in simple graphics?

In fact, I’m looking for a better (cleaner way) of doing this. I don’t want to use the use_fixed_projection render setting to allow the user to resize the window and see the game as large as he wants. And also to allow fullscreen toggle option.

1 Like

Use collection factory in fixed fit projection (SOLVED)
#2

This is easy to do if you use RenderCam.

3 Likes

#3

Thanks but I’d like to stay out of assets for now. I want to grasp the features of Defold before diving into extensions.[EDIT] Even if it makes my work more tedious. I’m just learning.
@Pkeod: You forgot to put a link to the library.^^
Rendercam

3 Likes

#4

You can, but it’s not as easy as with the GUI. You need to setup the clipping geometry and then configure your render script to use stencil tests to do the clipping via:



Maybe this could help you get started with the render script:

3 Likes

#5

You can also use render.set_viewport(). By default it’s always set to the full window, like so:

-- In render script update.
render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())

…but you can set it to whatever you want and the extra space will be left as your clear color. You’ll want your projection to match the same aspect ratio, or things will get stretched (if I recall correctly).

2 Likes