How to clip a game object's image / show only the part of the image contained in a certain region? (SOLVED)

Hi All,

I am new to Defold, and can’t figure out how to achieve the following:

20210821_180848

  1. The long “Bar” appear from left and moving to right (so at the beginning, the left part of the image is clipped)
  2. When the bar hit the end point, the right part of the bar that passed though the end point is clipped

I think I should either clip the game object’s image or show only the part of the image contained in a certain region, but have no idea how to achieve.

Much appreciated if anyone can share some insight!

Rectangular clipping in GUI is much easier. GUI also has 9patch which could also be used to solve your use case. 9patch has been requested for GO sprites but isn’t a feature yet.

For GOs, you need to draw masks to a render target and use that mask to composite the render predicate for your GOs.

5 Likes

Thanks! I think the GUI clipping is what I am looking for!

2 Likes