> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/gum-tool/tutorials-and-examples/examples/masking.md).

# Masking

## Introduction

Masking can be achieved to create "cut-out" effects such as rounded corners or images drawn over a circle shape. Masking is performed using render target containers and blend modes. Masking requires at least three objects:

1. A container to hold the masked objects. This container must be a render target container
2. The content to mask, such as a Sprite displaying an image
3. The mask shape, which can be a shape (such as a Circle) or another sprite with alpha that defines the mask

## Creating a Container

The first step is to create a container that will be the render target. A render target is required so that the mask can modify the alpha of its sibling in the container.

To contain a render target container, add a new Container object to your Screen or Component. If you want your entire Component to be the container, then you can check the Is Render Target variable on the container itself.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2FYUzJLQxWBTtKN727mFNF%2F04_06_10_48.png?alt=media&amp;token=a5f81170-fcc9-4dc7-ba2b-fd7a07fbe48a" alt=""><figcaption></figcaption></figure>

## Adding a Sprite

Next, add the content that you would like to have the mask applied to. For example, this could be an image. In this case, we will use a Sprite that is displaying a sample image. Add a sprite to your container and set its `Source File` to an image such as <https://picsum.photos/id/74/100/100>.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2FTIzXAd6mZEpMdSzP4Pyr%2F04_13_53_38.png?alt=media&amp;token=0e2590e0-d760-49de-b339-8eeda731afbb" alt=""><figcaption></figcaption></figure>

## Adding the Mask Shape

Next, add the shape that you would like to act as the mask. The mask can be an actual shape such as a circle, or it can be another image with custom alpha. For this example we'll use a circle.

Add a circle to your container and dock fill it so it takes the entire size of the container.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2FmU0GvQeYiT6VzpAHj4Wv%2F04_13_57_02.png?alt=media&amp;token=ee371386-f422-4f7e-bf53-de7d9ac4e1ec" alt=""><figcaption></figcaption></figure>

Next we'll modify the shape so it its alpha can be used. Set these variables:

* `Stroke Width` = 0
* `Is Filled` = true (checked)
* `Blend` = MinAlpha

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2FWR9jbvTOdCPoKQ6geIAU%2F04_14_00_04.png?alt=media&amp;token=7fed5ec0-c237-4644-a120-ed49e0d88776" alt=""><figcaption><p>Set Values on Circle for masking</p></figcaption></figure>

The `MinAlpha` value indicates that each pixel should use the minimum alpha, between the alpha that is on the image or the circle. In this case, the image is fully opaque, so the alpha is effectively the alpha of the circle. The outside of the circle shape is fully transparent so it removes the alpha from the image.

This same concept can be applied with other shapes, such as rectangles to produce rounded corners on images.

The mask uses the whole bounds of the shape, and a shape with both a fill and a stroke masks as one shape. For details see [Whole-Bounds Masking](/gum/gum-tool/gum-elements/general-properties/blend.md#whole-bounds-masking).

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2FmBMazBEkUS14x19rtJuM%2F04_14_02_09.png?alt=media&amp;token=6af88933-9130-47f7-8bc6-c9032632ee96" alt=""><figcaption><p>Rectangle mask using rounded corners</p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/gum-tool/tutorials-and-examples/examples/masking.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
