Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FlxTilemap.loadMapFromImage() #1525

Closed
Gama11 opened this issue Jun 10, 2015 · 3 comments
Closed

Add FlxTilemap.loadMapFromImage() #1525

Gama11 opened this issue Jun 10, 2015 · 3 comments
Assignees
Milestone

Comments

@Gama11
Copy link
Member

Gama11 commented Jun 10, 2015

...using FlxStringUtil.imageToCSV(). Suggested by @SeiferTim.

@Gama11
Copy link
Member Author

Gama11 commented Jun 10, 2015

Perhaps fromGraphic would be better for consistency with FlxSprite functions.

@Gama11 Gama11 added this to the 4.0.0 milestone Jun 23, 2015
@Gama11 Gama11 self-assigned this Jun 23, 2015
@Gama11
Copy link
Member Author

Gama11 commented Feb 1, 2016

No breaking changes necessary here, moving this to 4.1.0.

@Gama11 Gama11 modified the milestones: 4.1.0, 4.0.0 Feb 1, 2016
@Beeblerox
Copy link
Member

Beeblerox commented Apr 16, 2016

this method could look like this:

/**
     * Load the tilemap with image data and a tile graphic. 
     * Black pixels are flagged as 'solid' by default, non-black pixels are set as non-colliding. Black pixels must be PURE BLACK.
     * @param   MapGraphic      The image you want to use as a source of map data, where each pixel is a tile (or more than one tile if you change Scale's default value). Preferably black and white.
     * @param   Invert          Load white pixels as solid instead.
     * @param   Scale           Default is 1. Scale of 2 means each pixel forms a 2x2 block of tiles, and so on.
     * @param   ColorMap        An array of color values (alpha values are ignored) in the order they're intended to be assigned as indices
     * @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.
     * @param   AutoTile        Whether to load the map using an automatic tile placement algorithm (requires 16 tiles!).
     *                          Setting this to either AUTO or ALT will override any values you put for StartingIndex, DrawIndex, or CollideIndex.
     * @param   StartingIndex   Used to sort of insert empty tiles in front of the provided graphic.
     *                          Default is 0, usually safest ot leave it at that.  Ignored if AutoTile is set.
     * @param   DrawIndex       Initializes all tile objects equal to and after this index as visible.
     *                          Default value is 1. Ignored if AutoTile is set.
     * @param   CollideIndex    Initializes all tile objects equal to and after this index as allowCollisions = ANY.
     *                          Default value is 1.  Ignored if AutoTile is set.  
     *                          Can override and customize per-tile-type collision behavior using setTileProperties().
     * @return  A reference to this instance of FlxTilemap, for chaining as usual :)
     */
    public function loadMapFromGraphic(MapGraphic:FlxGraphicSource, Invert:Bool = false, Scale:Int = 1, ?ColorMap:Array<FlxColor>, TileGraphic:FlxTilemapGraphicAsset, TileWidth:Int = 0, TileHeight:Int = 0, ?AutoTile:FlxTilemapAutoTiling, StartingIndex:Int = 0, DrawIndex:Int = 1, CollideIndex:Int = 1)
    {
        var mapBitmap:BitmapData = FlxAssets.resolveBitmapData(MapGraphic);
        var mapData:String = FlxStringUtil.bitmapToCSV(mapBitmap, Invert, Scale, ColorMap);
        return loadMapFromCSV(mapData, TileGraphic, TileWidth, TileHeight, AutoTile, StartingIndex, DrawIndex, CollideIndex);
    }

Beeblerox added a commit that referenced this issue Apr 17, 2016
Aurel300 pushed a commit to larsiusprime/haxeflixel that referenced this issue Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants