Skip to content

Tutorials · Interfaces · Chapter 3

The bag

20 minutes Uses: Rect, Panel, Text, Grid, Clip

By the end

  • The bag’s window, bag, with a grid of sixteen slots in four columns
  • The first four slots showing the items, cut from the sheet by name
  • A clip that keeps what overflows inside the window
On this page

The bag’s window

The bag is a window at the right of the screen: a brown frame with a title, and inside it a paler panel that holds the slots. The panel carries a Clip, so that nothing in the bag can be drawn outside it.

  1. Select hud, click + Add node and choose Panel. Rename the node bag.
  2. In its Rect, set Anchor Min and Anchor Max both to 1, 0, Offset Min to -244, 160, Offset Max to -16, 412 and Pivot to 1, 0. That is a window 228 wide and 252 high, 16 in from the right edge of the screen and 160 down.
  3. In its Panel, set Color to 255, 255, 255, alpha 255, Texture to panel_brown.png and Border to 8.
  4. Select bag, click + Add node and choose Label. Rename the node bag_title. In its Rect, set Anchor Max to 1, 0, Offset Min to 16, 0, Offset Max to -16, 36 and Pivot to 0.5, 0. In its Text, set Text to Bag, Scale to 0.75, Color to 236, 227, 206, alpha 255, Outline to 63, 38, 49, alpha 255 and Outline Width to 1.
  5. Select bag, click + Add node and choose Panel. Rename the node bag_content. In its Rect, set Anchor Max to 1, 0, Offset Min to 12, 36, Offset Max to -12, 240 and Pivot to 0.5, 0. In its Panel, set Color to 255, 255, 255, alpha 255, Texture to panelInset_beige.png and Border to 6.
  6. Select bag_content, click Add component and choose ClipComponent. Leave its fields as they come.
bag_content selected, its Inspector narrowed with the search box, clip, to its Clip: Size 128.0 and 128.0, Anchor 0.5 and 0.5, Enabled ticked; the Viewport shows the HUD’s plate at the top left and the bag’s window at the right, its paler content panel outlined as the selection
Enabled
A Clip’s Enabled: whether it cuts right now. Ticked, everything under bag_content is cut at its rect, so a slot that reaches past the edge is drawn only inside it. Unticked, the children draw past the edge, as the last picture of the next section shows. A new Clip is ticked, and the bag leaves it so.

The Clip’s other two rows, Size and Anchor, are for a Clip on a node in the room. On an interface node the Clip cuts at the node’s own rect, so they stay as they come. Chapter 16 uses them.

Sixteen slots

The slots are sixteen small panels in a Grid, which places them in rows and columns so that you do not place each one.

  1. Select bag_content, click + Add node and choose Grid. Rename the node bag_grid. Its Rect stays as it comes, so it fills the content.
  2. In its Grid, set Cell to 44, 44, Spacing to 4, 4 and Padding to 8. Fit stays Columns and Columns stays 4.
  3. Select bag_grid, click + Add node and choose Panel. Rename the node bag_1. In its Panel, set Color to 255, 255, 255, alpha 255, Texture to panelInset_brown.png and Border to 6. Its Rect stays as it comes: the Grid places it.
  4. With bag_1 selected, press Ctrl+D. The copy comes selected, named bag_1 copy. Rename it bag_2. Press Ctrl+D again, rename the new copy bag_3, and go on until you have bag_16: fifteen copies in all.
bag_grid selected, its Inspector narrowed with the search box, grid, to its Grid: Fit Columns, Columns 4, Cell 44.0 and 44.0, Spacing 4.0 and 4.0, Padding 8.00; the Viewport shows the bag’s window at the right with its grid of sixteen slots outlined as the selection, and a red flask, a blue flask, a key and a green gem in the first row
Cell
Each slot’s size, in UI units. A Grid with Fit Columns, as this one has, works each slot’s width out from its own width and the number of columns, so only the second number, the slot’s height, is read. Here the content is 204 wide. The padding takes 16 of it, the three gaps 12, and four slots share the 176 left: 44 each, which is what the first number says too. A new Grid’s Cell is 64, 64.
Spacing
The gap between slots, across and then down, in UI units: 4, 4, the pale lines between the slots. A new Grid’s is 8, 8.
Padding
A Grid’s Padding: the margin kept inside its own edge on every side, in UI units: 8. A new Grid’s is 0.

The Grid’s other two rows, Fit and Columns, stay as they come: four columns, shared out of the grid’s width. Chapter 16 defines them.

The bag: a brown window titled BAG holding a paler panel with four columns of four brown slots, and a red flask, a blue flask, a golden key and a green gem in the first row
The bag: four columns of four.
The bag with Cell 56: the slots taller than they are wide, three rows showing and the fourth cut off by the bottom of the paler panel, so only a sliver of it shows
For comparison, Cell 56: the slots grow taller, not wider, and the grid runs past the content, where the Clip cuts it.
The bag with Cell 56 and the Clip unticked: three rows of tall slots, and the fourth row drawn in full below the paler panel, over the bag’s frame and out of the bag
For comparison, the same with the Clip off: the fourth row draws over the frame and out of the bag.

Pictures cut by name

The first four slots hold what the hero can carry: a red flask, a blue flask, a key and a green gem. Each is an Image inside its slot. The two flasks are on Tiny Dungeon’s sheet, and you cut them out by their names, not by numbers.

  1. Select bag_1, click + Add node and choose Image. Rename the node item_potion.
  2. In its Rect, set Anchor Min and Anchor Max both to 0.5, 0.5, Offset Min to -16, -16 and Offset Max to 16, 16.
  3. In its Panel, set Color to 255, 255, 255, alpha 255, Texture to tilemap_packed.png and Atlas Region to potion.
  4. Do the same in bag_2 for item_elixir, with Atlas Region elixir. In bag_3 add item_key, with Texture key.png and no region, and in bag_4 add item_gem, with Texture gem_green.png and no region.
item_potion selected, its Inspector narrowed with the search box, panel, to its Panel: Color white, Texture tilemap_packed.png, Border 0.00, UV Rect 0.00, 0.00, 1.00 and 1.00, Atlas Region potion, Tile 1.0 and 1.0; the Viewport shows the bag’s window at the right, the red flask in its first slot outlined as the selection
Atlas Region
The name of a piece of the picture, from the picture’s .meta file, drawn instead of the whole picture or the UV Rect. The name is looked up again every frame. potion and elixir are two of the eleven pieces Tiny Dungeon’s sheet names, below. A name the .meta does not have draws the whole picture, and the Console says so once. Empty, as a new Panel has it, draws the UV Rect.

Chapter 2’s portrait named the hero’s tile by four fractions. A region is the same job done by a name, which says what the piece is and not only where it is. The sheet’s .meta came with the starter, and holds these eleven:

RegionShowsTile
herothe hero98
door_closedthe door, closed45
door_openthe door, open21
shrine_topthe shrine’s gargoyle19
shrine_basethe shrine’s basin31
spikesa spike trap41
stairs_leftthe stairs, left end36
stairs_midthe stairs, middle37
stairs_rightthe stairs, right end39
potionthe red flask115
elixirthe blue flask116
Close up, the bag’s title BAG and its first row of slots: a red flask, a blue flask, a golden key and a green gem, each centred in a slot, with the top of the second row below
Close up: the four pictures in the bag’s first row.

The bag, its grid and its pictures

The bag’s window

NodeComponentFieldValue
bagRectAnchor Min1, 0
Anchor Max1, 0
Offset Min-244, 160
Offset Max-16, 412
Pivot1, 0
PanelColor255, 255, 255, alpha 255
Texturepanel_brown.png
Border8
bag_titleRectAnchor Max1, 0
Offset Min16, 0
Offset Max-16, 36
Pivot0.5, 0
TextTextBag
Scale0.75
Color236, 227, 206, alpha 255
Outline63, 38, 49, alpha 255
Outline Width1
bag_contentRectAnchor Max1, 0
Offset Min12, 36
Offset Max-12, 240
Pivot0.5, 0
PanelColor255, 255, 255, alpha 255
TexturepanelInset_beige.png
Border6
Clipevery fieldas it comes

The grid

NodeComponentFieldValue
bag_gridGridCell44, 44
Spacing4, 4
Padding8
bag_1 to bag_16PanelColor255, 255, 255, alpha 255
TexturepanelInset_brown.png
Border6

The item pictures

NodeComponentFieldValue
item_potion, item_elixir, item_key, item_gemRectAnchor Min0.5, 0.5
Anchor Max0.5, 0.5
Offset Min-16, -16
Offset Max16, 16
PanelColor255, 255, 255, alpha 255
item_potionTexture, Atlas Regiontilemap_packed.png, potion
item_elixirTexture, Atlas Regiontilemap_packed.png, elixir
item_keyTexturekey.png
item_gemTexturegem_green.png

Every other field of every node is as it comes.

Check it works