AudioAsset
Ease
FastString
FontAsset
NineSlice
PackedSprite
PackedSpriteID
RB
   HardwareSettings
   IRetroBlitGame
RBAsset
Rect2i
ShaderAsset
SoundReference
SpriteGrid
SpriteSheetAsset
TMXMapAsset
   TMXLayer
   TMXLayerLoadState
   TMXObject
   TMXObjectGroup
   TMXProperties
Vector2i

NineSlice.NineSlice

Method

public  NineSlice(Rect2i topLeftCornerRect, Rect2i topSideRect, Rect2i topRightCornerRect, Rect2i leftSideRect, Rect2i middleRect, Rect2i rightSideRect, Rect2i bottomLeftCornerRect, Rect2i bottomSideRect, Rect2i bottomRightCornerRect)
public  NineSlice(Rect2i topLeftCornerRect, Rect2i topSideRect, Rect2i middleRect)
public  NineSlice(PackedSpriteID topLeftCornerID, PackedSpriteID topSideID, PackedSpriteID topRightCornerID, PackedSpriteID leftSideID, PackedSpriteID middleID, PackedSpriteID rightSideID, PackedSpriteID bottomLeftCornerID, PackedSpriteID bottomSideID, PackedSpriteID bottomRightCornerID)
public  NineSlice(PackedSpriteID topLeftCornerID, PackedSpriteID topSideID, PackedSpriteID middleID)
public  NineSlice(PackedSprite topLeftCorner, PackedSprite topSide, PackedSprite topRightCorner, PackedSprite leftSide, PackedSprite middle, PackedSprite rightSide, PackedSprite bottomLeftCorner, PackedSprite bottomSide, PackedSprite bottomRightCorner)
public  NineSlice(PackedSprite topLeftCorner, PackedSprite topSide, PackedSprite middle)
public  NineSlice(string topLeftCornerName, string topSideName, string topRightCornerName, string leftSideName, string middleName, string rightSideName, string bottomLeftCornerName, string bottomSideName, string bottomRightCornerName)
public  NineSlice(string topLeftCornerName, string topSideName, string middleName)
public  NineSlice(FastString topLeftCornerName, FastString topSideName, FastString topRightCornerName, FastString leftSideName, FastString middleName, FastString rightSideName, FastString bottomLeftCornerName, FastString bottomSideName, FastString bottomRightCornerName)
public  NineSlice(FastString topLeftCornerName, FastString topSideName, FastString middleName)

Parameters

topLeftCornerRect Rect2i Top left corner rect
topSideRect Rect2i Top side rect
topRightCornerRect Rect2i Top right corner rect
leftSideRect Rect2i Left side rect
middleRect Rect2i Middle rect
rightSideRect Rect2i Right side rect
bottomLeftCornerRect Rect2i Bottom left corner rect
bottomSideRect Rect2i Bottom side rect
bottomRightCornerRect Rect2i Bottom right corner rect
topLeftCornerID PackedSpriteID Top left corner sprite ID
topSideID PackedSpriteID Top side sprite ID
topRightCornerID PackedSpriteID Top right corner sprite ID
leftSideID PackedSpriteID Left side sprite ID
middleID PackedSpriteID Middle sprite ID
rightSideID PackedSpriteID Right side sprite ID
bottomLeftCornerID PackedSpriteID Bottom left corner sprite ID
bottomSideID PackedSpriteID Bottom side sprite ID
bottomRightCornerID PackedSpriteID Bottom right corner sprite ID
topLeftCorner PackedSprite Top left corner PackedSprite
topSide PackedSprite Top side PackedSprite
topRightCorner PackedSprite Top right corner PackedSprite
leftSide PackedSprite Left side PackedSprite
middle PackedSprite Middle PackedSprite
rightSide PackedSprite Right side PackedSprite
bottomLeftCorner PackedSprite Bottom left corner PackedSprite
bottomSide PackedSprite Bottom side PackedSprite
bottomRightCorner PackedSprite Bottom right corner PackedSprite
topLeftCornerName string Top left corner sprite name
topSideName string Top side sprite name
topRightCornerName string Top right corner sprite name
leftSideName string Left side sprite name
middleName string Middle sprite name
rightSideName string Right side sprite name
bottomLeftCornerName string Bottom left corner sprite name
bottomSideName string Bottom side sprite name
bottomRightCornerName string Bottom right corner sprite name
topSideName FastString Top side rect sprite name
middleName FastString Middle rect sprite name

Returns

Nothing.

Description

Creates a new NineSlice image definition. A nine-slice sprite is a special kind of sprite usually used to draw rectangular shapes for UI elements. A nine-slice sprite is defined by up to 9 separate sprites that are arranged and repeated as needed in such a way that they can fill any rectangular area.


Nine parts that make up a nine slice image

The pieces A, C, G, and I are always drawn in the corners of the nine-slice sprite. B and H are repeated horizontally. E and F are repeated vertically. Finally, X is repeated in both directions to fill the middle of the nine-slice sprite.

For best results each of these groups of pieces should be the same height:

  • A, B, C
  • E, F
  • G, H, I
These groups should be the same width:
  • A, E, G
  • B, H
  • C, F, I
The center piece X can be of any size.

The pieces that make up a nine-slice image should not be too small to limit the amount of times they have to be repeated to fill your nine-slice sprite.

In some cases, such as in the image above, many of the pieces are symmetric, for convenience there are NineSlice.NineSlice overloads that take only srcTopLeftCornerRect, srcTopSideRect, and srcMiddleRect and simply rotate and mirror the remaining pieces automatically.

You can specify the pieces of a nine-slice image through either source rectangles, or sprite ids for sprites in a sprite pack.

Example

SpriteSheetAsset  uiSprites = new SpriteSheetAsset();
NineSlice dialogFrame;

void Initialize() {
    uiSprites.Load("spritesheets/ui");
    dialogFrame = new NineSlice(
        new Rect2i(0088),
        new Rect2i(8088),
        new Rect2i(16088));
}

void Render() {
    RB.SpriteSheetSet(uiSprites);

    var dialogRect = new Rect2i(10010012864);

    // Draw a dialog frame using the predefined NineSlice
    RB.DrawNineSlice(dialogRect, dialogFrame);
    RB.Print(
        dialogRect, Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER,
        "It's boring to go alone, take me!");
}

See Also

RB.DrawNineSlice
RB.SpriteSheetSet
SpriteSheetAsset

See Docs

Features - Nine-Slice Sprite
Features - Sprite Sheets
Features - Sprite Packs