NinePatch native support

WaveEngine 2.4.0 includes official native support for NinePatch textures (also known as 9-slice). To know more about what that kind of textures is, read our previous post about it.

As this version allows you to add textures and mark them as “NinePatchType: FromTexture”. This option will be automatically selected if your texture has the extension “*.9.png”.

When this mode is selected, the exporter will extract the stretch and content regions from the texture and remove them from the final asset. Keep it in mind if you need power of two textures (e.g., if your final texture must be 256×256, the source image size must be 258×258)

After that you can render this texture in both modes: simple or sliced modifying the DrawMode property of the existing SpriteRenderer component. Simple mode is active by default and scales the texture uniformly, while the slide mode activates the NinePatch render.

Multi Stretch support

Wave Engine supports multi stretch areas. This is useful if we need to maintain certain areas unscaled in the middle of stretchable ones. When the sprite is scaled, the proportion between the different stretchable areas will be respected, so it can be used to adjust the final layout.

If you activate DebugLines mode in the camera properties panel, you can see the different stretchable areas of the NinePatch tinted in green and pink.

New Texture2D properties

NinePatch support aggregates 3 new properties to the Texture2D class:

  • ContentArea: Rectangle that indicates the content area of the texture. Useful if we want to render text inside a NinePatch panel.
  • HorizontalScalableAnchors: Point[] that represents the horizontal segments that indicate the horizontally scalable areas of the texture. X indicates the horizontal pixel coordinate where the area begins and Y indicates the width of the area.
  • VerticalScalableAnchors: Point[] that represents the vertical segments that indicate the vertical scalable areas of the texture. X indicates the vertical pixel coordinate where the area begins and Y indicates the height of the area.

Those properties are only available when the texture is marked with “NinePatchType: FromTexture” within the Asset Viewer, otherwise, those will be null.

Leave a Reply

Your email address will not be published. Required fields are marked *