text stringlengths 0 897 |
|---|
```terminal |
]td.cellSize = 32 |
]td.cellSize = 320 |
]td.cellSize = [128,32] |
]td.cellSize = 64 |
``` |
Note that just like the `tileSetTileSize` property, you can specify `cellSize` as either a simple number for square cells, or as a `[width, height]` list for non-square cells. |
Changing the tile size is how you can scale a tile display. What about scrolling? That uses the same `scrollX` and `scrollY` properties you already saw on `PixelDisplay` and `SpriteDisplay`. |
```terminal |
]for x in range(0,100); td.scrollX = x; wait 0.1; end for |
]td.scrollX = 0 |
``` |
A tile display could be configured to be many times bigger than the actual screen, with different areas being scrolled into view as needed during a run. |
## Using Cells |
You've already been using tile indexes with the `.clear` method, to clear the whole tile display to the same cell. Now let's learn to set, read, and tint specific cells. |
The methods for doing this are very similar to those you would use on a `TextDisplay` (Day 17): `cell(column, row)` to read the tile index at a given column and row, or `setCell column, row, index` to set it. And just like a `TextDisplay`, rows count up from the bottom, and columns count from the left side of the disp... |
```terminal |
]td.setCell 0, 0, 8 |
``` |
Now try using the `cell` method to read back the tile index at several positions. |
```terminal |
]td.cell 0,0 |
8 |
]td.cell 1,0 |
20 |
``` |
Simple, right? Cover up the code below, and see if you can solve the following challenge without looking: change the cell that's 6th from the left, and 3rd from the bottom, into a white diamond. (Remember that rows and columns begin at 0, not at 1.) |
```terminal |
]td.setCell 5, 2, 40 |
``` |
Did you get it right? |
D> Make up some more challenges for yourself if you need more practice; the computer is a calm and infinitely patient teacher. |
Instead of assigning a tile index to a cell, you can also set it to `null`, which means "don't draw any tile here at all." In fact this is what the `.clear` method does to all cells if you don't specify an index value. Go ahead and try it now: |
```terminal |
]td.setCell 3, 3, null |
``` |
The other thing you can do with tile display cells is tint them, just like sprites. If you tint a pixel that's white in the source image, it comes out exactly the tint color; but if the source image is darker, then you get a darker version of the tint color. That's why white images are so useful. In fact, this `Simp... |
```terminal |
]td.setCellTint 5, 2, color.orange |
]td.setCellTint 5, 1, color.gray |
``` |
The first line above tints that white diamond a nice strong orange. The second line tints a blue circle gray, which really just makes it a darker blue. |
Hopefully you see how by assigning different tile indexes and/or tints to different cells, you can build a complex display that looks like a map, or a platformer game level, or anything else that has a basically grid-like structure. |
## Overlap and Offset |
So far we have only seen cells arranged into a neat square or rectangular grid. Tile displays in Mini Micro are more versatile than that, however. |
First, it is possible to set the cells in the display to overlap horizontally, vertically, or both. To do this you assign to the `overlap` property a list that contains the desired horizontal and vertical overlap. For example: |
```terminal |
]td.overlap = [0, 8] |
``` |
This scrunches the cells so that they overlap in Y. This can be useful for certain art styles, where each tile contains bits at the top that overlap, for example, grass or flowers that stick up from the ground on a grass tile. When tiles are overlapped, they're always layered so that lower rows on the screen are draw... |
The second trick you can do with the cell arrangement is to offset odd-numbered rows or columns by some fraction of the cell width. This is useful in making isometric or hexagonal maps. Let's start with an isometric map. That's one where the map is made of little diamonds that fit together neatly, as if you were loo... |
{width: "50%"} |
 |
To do set this up, we'll use a diamond-shaped tile with a rectangular cell size. Then we'll use `overlap` to make it so that each row overlaps the one above it, and the `oddRowOffset` property to shift the odd-number rows over by one half the cell width. Try it: |
```terminal |
]td.overlap = 0 |
]td.clear 40 |
]td.cellSize = [64, 48] |
]td.overlap = [0, 24] |
]td.oddRowOffset = 0.5 |
``` |
Line 1 above just clears out the `overlap` values from our previous experiment. Line 2 clears the display to a white diamond tile, and line 3 squashes that vertically so that each cell on screen is wider than it is tall. Line 4 makes the rows overlap, and then — here's the real trick — line 5 shifts the odd rows (i.e... |
The other use for shifting odd rows or columns is to make a hexagonal display. The basic idea here is the same: make your tiles overlap, and then add a row or column offset, depending on which way your hexagons are rotated. We'll walk through each case, using circle tiles at first (which make it slightly easier to se... |
First, let's get back to an ordinary square grid of circles. |
```terminal |
]td.oddRowOffset = 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.