Rotating and Scaling Clipped Contents
Introduction
The Clips Children and Is Render Target properties clip their children to an axis-aligned rectangle. Because the clip region stays aligned to the screen, rotating a container that clips its children leaves the clip region unrotated, so the result looks broken.
To rotate (or scale) a container and keep its contents clipped, you render the container to a render target and display that render target through a Sprite. The Sprite can then be rotated, scaled, positioned, and stacked like any other Gum object, and the clipping rotates along with it.

The Two-Object Pattern
This effect uses two objects:
A Container with Is Render Target set to
true. This container holds the content you want to clip, and it clips its children automatically.A Sprite with its Render Target Texture Source set to the container above. The
Spritedisplays the container's render target and can be freely rotated and scaled.

The source container (which has Use Render Terget set to true) can even be made invisible:

Step by Step
Create a Container and add the children you want to clip and rotate.
Select the Container and set its Is Render Target value to
true. Its children are now clipped to the container's bounds.Create a Sprite.
Select the Sprite and set its Render Target Texture Source value to the container created in step 1. The dropdown lists all containers in the current element that have Is Render Target set to
true.Set the Sprite's Rotation (and optionally its
WidthandHeight) to rotate and scale the clipped contents.

Notes
A container with Is Render Target set to
trueperforms its layout and rendering even when itsVisiblevalue isfalse. Set the source container'sVisibletofalseto hide the original while still displaying it through theSprite.Children inside the render target container are not interactive while displayed through the
Sprite, because input is handled by the original (invisible) container rather than the rotatedSprite.
See Also
RenderTargetTextureSource — the same pattern in code
Last updated
Was this helpful?

