C# Class XnaFlixel.FlxTilemap

This is a traditional tilemap display and collision class. It takes a string of comma-separated numbers and then associates those values with tiles from the sheet you pass in. It also includes some handy static parsers that can convert arrays or PNG files into strings that can be successfully loaded.
Inheritance: FlxObject
Afficher le fichier Open project: jsbeckr/XnaFlixel

Méthodes publiques

Свойство Type Description
ImgAuto Microsoft.Xna.Framework.Graphics.Texture2D
ImgAutoAlt Microsoft.Xna.Framework.Graphics.Texture2D
auto int
collideIndex int
drawIndex int
heightInTiles int
refresh bool
startingIndex int
totalTiles int
widthInTiles int

Protected Properties

Свойство Type Description
_block FlxObject
_boundsVisible bool
_data int[]
_flashRect Microsoft.Xna.Framework.Rectangle
_flashRect2 Microsoft.Xna.Framework.Rectangle
_rects List
_screenCols int
_screenRows int
_tileBitmap Microsoft.Xna.Framework.Graphics.Texture2D
_tileHeight int
_tileWidth int

Méthodes publiques

Méthode Description
FlxTilemap ( ) : System

The tilemap constructor just initializes some basic variables.

Overlaps ( FlxObject Core ) : bool

Checks for overlaps between the provided object and any tiles above the collision index. @param Core The FlxObject you want to check against.

OverlapsPoint ( float X, float Y ) : bool

Checks to see if a point in 2D space overlaps a solid tile. @param X The X coordinate of the point. @param Y The Y coordinate of the point. @param PerPixel Not available in FlxTilemap, ignored. @return Whether or not the point overlaps this object.

OverlapsPoint ( float X, float Y, bool PerPixel ) : bool
PreCollide ( FlxObject Object ) : void

FlxU.collide() (and thus FlxObject.collide()) call this function each time two objects are compared to see if they collide. It doesn't necessarily mean these objects WILL collide, however. @param Object The FlxObject you're about to run into.

RefreshHulls ( ) : void

Called by FlxObject.updateMotion() and some constructors to rebuild the basic collision data for this object.

Render ( SpriteBatch spriteBatch ) : void

Draws the tilemap.

arrayToCSV ( int Data, int Width ) : string

Converts a one-dimensional array of tile data to a comma-separated string. @param Data An array full of integer tile references. @param Width The number of tiles in each row. @return A comma-separated string containing the level data in a FlxTilemap-friendly format.

bitmapToCSV ( Microsoft.Xna.Framework.Graphics.Texture2D bitmapData ) : string

Converts a BitmapData object to a comma-separated string. Black pixels are flagged as 'solid' by default, non-black pixels are set as non-colliding. Black pixels must be PURE BLACK. @param bitmapData A Texture2D, preferably black and white. @param Invert Load white pixels as solid instead. @return A comma-separated string containing the level data in a FlxTilemap-friendly format.

bitmapToCSV ( Microsoft.Xna.Framework.Graphics.Texture2D bitmapData, bool Invert ) : string
follow ( ) : void

Call this function to lock the automatic camera to the map's edges. @param Border Adjusts the camera follow boundary by whatever number of tiles you specify here. Handy for blocking off deadends that are offscreen, etc. Use a negative number to add padding instead of hiding the edges.

follow ( int Border ) : void
getTile ( int X, int Y ) : int

Check the value of a particular tile. @param X The X coordinate of the tile (in tiles, not pixels). @param Y The Y coordinate of the tile (in tiles, not pixels). @return A uint containing the value of the tile at this spot in the array.

getTileByIndex ( int Index ) : int

Get the value of a tile in the tilemap by index. @param Index The slot in the data array (Y/// widthInTiles + X) where this tile is stored. @return A uint containing the value of the tile at this spot in the array.

loadMap ( string MapData, Microsoft.Xna.Framework.Graphics.Texture2D TileGraphic ) : FlxTilemap

Load the tilemap with string data and a tile graphic. @param MapData A string of comma and line-return delineated indices indicating what order the tiles should go in. @param TileGraphic All the tiles you want to use, arranged in a strip corresponding to the numbers in MapData. @param TileWidth The width of your tiles (e.g. 8) - defaults to height of the tile graphic if unspecified. @param TileHeight The height of your tiles (e.g. 8) - defaults to width if unspecified. @return A pointer this instance of FlxTilemap, for chaining as usual :)

loadMap ( string MapData, Microsoft.Xna.Framework.Graphics.Texture2D TileGraphic, int TileWidth, int TileHeight ) : FlxTilemap
ray ( int StartX, int StartY, int EndX, int EndY, Vector2 Result, int Resolution ) : bool

Shoots a ray from the start point to the end point. If/when it passes through a tile, it stores and returns that point. @param StartX The X component of the ray's start. @param StartY The Y component of the ray's start. @param EndX The X component of the ray's end. @param EndY The Y component of the ray's end. @param Result A Point object containing the first wall impact. @param Resolution Defaults to 1, meaning check every tile or so. Higher means more checks! @return Whether or not there was a collision between the ray and a colliding tile.

setCallback ( int Tile, int Callback, int Range ) : void

Bind a function Callback(Core:FlxCore,X:uint,Y:uint,Tile:uint) to a range of tiles. @param Tile The tile to trigger the callback. @param Callback The function to trigger. Parameters should be (Core:FlxCore,X:uint,Y:uint,Tile:uint). @param Range If you want this callback to work for a bunch of different tiles, input the range here. Default value is 1.

setTile ( int X, int Y, int Tile ) : bool

Change the data and graphic of a tile in the tilemap. @param X The X coordinate of the tile (in tiles, not pixels). @param Y The Y coordinate of the tile (in tiles, not pixels). @param Tile The new integer data you wish to inject. @param UpdateGraphics Whether the graphical representation of this tile should change. @return Whether or not the tile was actually changed.

setTile ( int X, int Y, int Tile, bool UpdateGraphics ) : bool
setTileByIndex ( int Index, int Tile, bool UpdateGraphics ) : bool

Change the data and graphic of a tile in the tilemap. @param Index The slot in the data array (Y/// widthInTiles + X) where this tile is stored. @param Tile The new integer data you wish to inject. @param UpdateGraphics Whether the graphical representation of this tile should change. @return Whether or not the tile was actually changed.

Méthodes protégées

Méthode Description
autoTile ( int Index ) : void

An internal function used by the binary auto-tilers. @param Index The index of the tile you want to analyze.

generateBoundingTiles ( ) : void

Generates a bounding box version of the tiles, flixel should call this automatically when necessary.

updateTile ( int Index ) : void

Internal function used in setTileByIndex() and the constructor to update the map. @param Index The index of the tile you want to update.

Method Details

FlxTilemap() public méthode

The tilemap constructor just initializes some basic variables.
public FlxTilemap ( ) : System
Résultat System

Overlaps() public méthode

Checks for overlaps between the provided object and any tiles above the collision index. @param Core The FlxObject you want to check against.
public Overlaps ( FlxObject Core ) : bool
Core FlxObject
Résultat bool

OverlapsPoint() public méthode

Checks to see if a point in 2D space overlaps a solid tile. @param X The X coordinate of the point. @param Y The Y coordinate of the point. @param PerPixel Not available in FlxTilemap, ignored. @return Whether or not the point overlaps this object.
public OverlapsPoint ( float X, float Y ) : bool
X float
Y float
Résultat bool

OverlapsPoint() public méthode

public OverlapsPoint ( float X, float Y, bool PerPixel ) : bool
X float
Y float
PerPixel bool
Résultat bool

PreCollide() public méthode

FlxU.collide() (and thus FlxObject.collide()) call this function each time two objects are compared to see if they collide. It doesn't necessarily mean these objects WILL collide, however. @param Object The FlxObject you're about to run into.
public PreCollide ( FlxObject Object ) : void
Object FlxObject
Résultat void

RefreshHulls() public méthode

Called by FlxObject.updateMotion() and some constructors to rebuild the basic collision data for this object.
public RefreshHulls ( ) : void
Résultat void

Render() public méthode

Draws the tilemap.
public Render ( SpriteBatch spriteBatch ) : void
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch
Résultat void

arrayToCSV() public static méthode

Converts a one-dimensional array of tile data to a comma-separated string. @param Data An array full of integer tile references. @param Width The number of tiles in each row. @return A comma-separated string containing the level data in a FlxTilemap-friendly format.
public static arrayToCSV ( int Data, int Width ) : string
Data int
Width int
Résultat string

autoTile() protected méthode

An internal function used by the binary auto-tilers. @param Index The index of the tile you want to analyze.
protected autoTile ( int Index ) : void
Index int
Résultat void

bitmapToCSV() public static méthode

Converts a BitmapData object to a comma-separated string. Black pixels are flagged as 'solid' by default, non-black pixels are set as non-colliding. Black pixels must be PURE BLACK. @param bitmapData A Texture2D, preferably black and white. @param Invert Load white pixels as solid instead. @return A comma-separated string containing the level data in a FlxTilemap-friendly format.
public static bitmapToCSV ( Microsoft.Xna.Framework.Graphics.Texture2D bitmapData ) : string
bitmapData Microsoft.Xna.Framework.Graphics.Texture2D
Résultat string

bitmapToCSV() public static méthode

public static bitmapToCSV ( Microsoft.Xna.Framework.Graphics.Texture2D bitmapData, bool Invert ) : string
bitmapData Microsoft.Xna.Framework.Graphics.Texture2D
Invert bool
Résultat string

follow() public méthode

Call this function to lock the automatic camera to the map's edges. @param Border Adjusts the camera follow boundary by whatever number of tiles you specify here. Handy for blocking off deadends that are offscreen, etc. Use a negative number to add padding instead of hiding the edges.
public follow ( ) : void
Résultat void

follow() public méthode

public follow ( int Border ) : void
Border int
Résultat void

generateBoundingTiles() protected méthode

Generates a bounding box version of the tiles, flixel should call this automatically when necessary.
protected generateBoundingTiles ( ) : void
Résultat void

getTile() public méthode

Check the value of a particular tile. @param X The X coordinate of the tile (in tiles, not pixels). @param Y The Y coordinate of the tile (in tiles, not pixels). @return A uint containing the value of the tile at this spot in the array.
public getTile ( int X, int Y ) : int
X int
Y int
Résultat int

getTileByIndex() public méthode

Get the value of a tile in the tilemap by index. @param Index The slot in the data array (Y/// widthInTiles + X) where this tile is stored. @return A uint containing the value of the tile at this spot in the array.
public getTileByIndex ( int Index ) : int
Index int
Résultat int

loadMap() public méthode

Load the tilemap with string data and a tile graphic. @param MapData A string of comma and line-return delineated indices indicating what order the tiles should go in. @param TileGraphic All the tiles you want to use, arranged in a strip corresponding to the numbers in MapData. @param TileWidth The width of your tiles (e.g. 8) - defaults to height of the tile graphic if unspecified. @param TileHeight The height of your tiles (e.g. 8) - defaults to width if unspecified. @return A pointer this instance of FlxTilemap, for chaining as usual :)
public loadMap ( string MapData, Microsoft.Xna.Framework.Graphics.Texture2D TileGraphic ) : FlxTilemap
MapData string
TileGraphic Microsoft.Xna.Framework.Graphics.Texture2D
Résultat FlxTilemap

loadMap() public méthode

public loadMap ( string MapData, Microsoft.Xna.Framework.Graphics.Texture2D TileGraphic, int TileWidth, int TileHeight ) : FlxTilemap
MapData string
TileGraphic Microsoft.Xna.Framework.Graphics.Texture2D
TileWidth int
TileHeight int
Résultat FlxTilemap

ray() public méthode

Shoots a ray from the start point to the end point. If/when it passes through a tile, it stores and returns that point. @param StartX The X component of the ray's start. @param StartY The Y component of the ray's start. @param EndX The X component of the ray's end. @param EndY The Y component of the ray's end. @param Result A Point object containing the first wall impact. @param Resolution Defaults to 1, meaning check every tile or so. Higher means more checks! @return Whether or not there was a collision between the ray and a colliding tile.
public ray ( int StartX, int StartY, int EndX, int EndY, Vector2 Result, int Resolution ) : bool
StartX int
StartY int
EndX int
EndY int
Result Vector2
Resolution int
Résultat bool

setCallback() public méthode

Bind a function Callback(Core:FlxCore,X:uint,Y:uint,Tile:uint) to a range of tiles. @param Tile The tile to trigger the callback. @param Callback The function to trigger. Parameters should be (Core:FlxCore,X:uint,Y:uint,Tile:uint). @param Range If you want this callback to work for a bunch of different tiles, input the range here. Default value is 1.
public setCallback ( int Tile, int Callback, int Range ) : void
Tile int
Callback int
Range int
Résultat void

setTile() public méthode

Change the data and graphic of a tile in the tilemap. @param X The X coordinate of the tile (in tiles, not pixels). @param Y The Y coordinate of the tile (in tiles, not pixels). @param Tile The new integer data you wish to inject. @param UpdateGraphics Whether the graphical representation of this tile should change. @return Whether or not the tile was actually changed.
public setTile ( int X, int Y, int Tile ) : bool
X int
Y int
Tile int
Résultat bool

setTile() public méthode

public setTile ( int X, int Y, int Tile, bool UpdateGraphics ) : bool
X int
Y int
Tile int
UpdateGraphics bool
Résultat bool

setTileByIndex() public méthode

Change the data and graphic of a tile in the tilemap. @param Index The slot in the data array (Y/// widthInTiles + X) where this tile is stored. @param Tile The new integer data you wish to inject. @param UpdateGraphics Whether the graphical representation of this tile should change. @return Whether or not the tile was actually changed.
public setTileByIndex ( int Index, int Tile, bool UpdateGraphics ) : bool
Index int
Tile int
UpdateGraphics bool
Résultat bool

updateTile() protected méthode

Internal function used in setTileByIndex() and the constructor to update the map. @param Index The index of the tile you want to update.
protected updateTile ( int Index ) : void
Index int
Résultat void

Property Details

ImgAuto public_oe static_oe property

public static Texture2D,Microsoft.Xna.Framework.Graphics ImgAuto
Résultat Microsoft.Xna.Framework.Graphics.Texture2D

ImgAutoAlt public_oe static_oe property

public static Texture2D,Microsoft.Xna.Framework.Graphics ImgAutoAlt
Résultat Microsoft.Xna.Framework.Graphics.Texture2D

_block protected_oe property

protected FlxObject _block
Résultat FlxObject

_boundsVisible protected_oe property

protected bool _boundsVisible
Résultat bool

_data protected_oe property

protected int[] _data
Résultat int[]

_flashRect protected_oe property

Rendering helper.
protected Rectangle,Microsoft.Xna.Framework _flashRect
Résultat Microsoft.Xna.Framework.Rectangle

_flashRect2 protected_oe property

protected Rectangle,Microsoft.Xna.Framework _flashRect2
Résultat Microsoft.Xna.Framework.Rectangle

_rects protected_oe property

protected List _rects
Résultat List

_screenCols protected_oe property

protected int _screenCols
Résultat int

_screenRows protected_oe property

protected int _screenRows
Résultat int

_tileBitmap protected_oe property

protected Texture2D,Microsoft.Xna.Framework.Graphics _tileBitmap
Résultat Microsoft.Xna.Framework.Graphics.Texture2D

_tileHeight protected_oe property

protected int _tileHeight
Résultat int

_tileWidth protected_oe property

protected int _tileWidth
Résultat int

auto public_oe property

Set this flag to use one of the 16-tile binary auto-tile algorithms (OFF, AUTO, or ALT).
public int auto
Résultat int

collideIndex public_oe property

What tile index will you start colliding with (default: 1).
public int collideIndex
Résultat int

drawIndex public_oe property

What tile index will you start drawing with (default: 1) NOTE: should always be >= startingIndex. If you want to change it, do so before calling loadMap().
public int drawIndex
Résultat int

heightInTiles public_oe property

Read-only variable, do NOT recommend changing after the map is loaded!
public int heightInTiles
Résultat int

refresh public_oe property

Set this flag to true to force the tilemap buffer to refresh on the next render frame.
public bool refresh
Résultat bool

startingIndex public_oe property

The first index of your tile sheet (default: 0) If you want to change it, do so before calling loadMap().
public int startingIndex
Résultat int

totalTiles public_oe property

Read-only variable, do NOT recommend changing after the map is loaded!
public int totalTiles
Résultat int

widthInTiles public_oe property

Read-only variable, do NOT recommend changing after the map is loaded!
public int widthInTiles
Résultat int