Created
October 2, 2012 21:46
-
-
Save jgranick/3823511 to your computer and use it in GitHub Desktop.
How to use nme.display.Tilesheet (NME recipe)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nme.display.Sprite; | |
import nme.display.Tilesheet; | |
import nme.geom.Rectangle; | |
import nme.Assets; | |
public class TilesheetExample extends Sprite { | |
public function new () { | |
super (); | |
var tilesheet = new Tilesheet (Assets.getBitmapData ("example.png")); | |
tilesheet.addTileRect (new Rectangle (0, 0, 100, 100)); | |
tilesheet.addTileRect (new Rectangle (100, 0, 100, 100)); | |
tilesheet.drawTiles (graphics, [ 0, 0, 0, 100, 0, 1 ]); | |
} | |
} |
I can't find Tilesheet file at source tree (under nme.display), so I have a question - does addTileRect return ID of new created tile?
I can't find Tilesheet under nme.display either, only browser.display and native.display...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you call "addTileRect", it generates a new tile ID. To draw the first rectangle from the source bitmap, use a tile ID of 0. To draw the second rectangle, use a tile ID of 1, and so on.
The array that drawTiles expects begins with the X, Y and tile ID that you wish to draw. In the example above, it will draw twice, once at (0, 0) and once at (100, 0).
The third parameter of "drawTiles" is a boolean value for whether the render should be smoothed, and the fourth accepts optional flags.
You can set flags for Tilesheet.TILE_SCALE, Tilesheet.TILE_ROTATION, Tilesheet.RGB and Tilesheet.TILE_ALPHA to extend the values in the draw array. Depending on which flags you use, the array expands from [ x, y, tileID ... ] to [ x, y, tile ID, scale, rotation, red, green, blue, alpha ... ]