Flixel Learning Note 002 Loading map (i)

Source: Internet
Author: User

This article references the official code example cameras, code in HTTPS://GITHUB.COM/PHMONGEAU/SPLITSCREEN/TREE/MASTER/SRC.

First, a few panes were drawn with Windows, and the size was 20*20.

Then, referring to the official code example, wrote a piece of code:

1 Package org2 {3     Importorg.flixel.FlxState;4     ImportOrg.flixel.FlxTilemap;5     6     /**7      * ...8 * @author quanjp [email protected]9      */Ten      Public classGameStateextendsflxstate One     { A          -[Embed (Source =".. /maptile.png ")]Private varImgtile:class; -          theProtectedvarMap:flxtilemap; -          -          Public functiongamestate () -         { +             varData:array = [2, 2, 2, 1, 1, 1, 2, -2, 0, 2, 1, 1, 2, 0, +2, 2, 2, 1, 2, 0, 0]; AMap =NewFlxtilemap (); atMap.loadmap (Flxtilemap.arraytocsv (data, 7), Imgtile, 20, 20); - Add (map); -         } -          -     } -  in}

Random map data, compiled into this:

Do not know why, did not show the red part.

Let's just analyze the code. Here is the code I commented on, of course, the code was written by Adam Atomic, the original author, and I just annotated it.

1         /**2 * Load a tile map with a string data and tile image. 3          * 4 * @param MapData a series of indicators with ', ' and ' \ n ' to indicate in what order the tiles should go in. 5 * @param tilegraphic The tiles you want to use, line up the corresponding numbers in MapData. 6 * @param tilewidth tile width (e.g. 8)-The width of the tile bitmap is not set by default. 7 * @param tileheight tile width (e.g. 8)-The width of the tile is not set by default. 8 * @param autotile whether to load the map using the automatic tile mapping algorithm. Setting this to either AUTO or ALT would override any values you put for Startingindex, Drawindex, or Collideindex.9 * @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.Ten * @param drawindex initializes all tiles objects equal to and after this index as visible.  Default value is 1. Ignored if Autotile is set. One * @param collideindex initializes all tiles objects equal to and after this index as Allowcollisions = A  NY.  Default value is 1.  Ignored if Autotile is set.    Can Override and customize Per-tile-type collision behavior using <code>settileproperties () </code>.  A          *  - * @return A Pointer This instance of FLXTILEMAP, for chaining as usual:) -          */ the          Public functionLoadmap (mapdata:string, Tilegraphic:class, tilewidth:uint=0, tileheight:uint=0, Autotile:uint=off, StartingIndex: Uint=0, Drawindex:uint=1, collideindex:uint=1): Flxtilemap -         { -Auto =Autotile; -_startingindex =Startingindex; +  -             //identifies the map dimension based on the data string.  +             varColumns:array; A             varRows:array = Mapdata.split ("\ n");//use ' \ n ' to divide the input mapdata into a string array atHeightintiles = Rows.length;//map height (in squares) is the length of rows -_data =NewArray (); -             varRow:uint = 0;//How many lines are processed?  -             varColumn:uint; -              while(Row <heightintiles) -             { incolumns = Rows[row++].split (",");//use ', ' to divide the elements of a column -                 if(Columns.length <= 1) to                 { +Heightintiles = heightInTiles-1; -                     Continue;//map Height minus 1 If a blank line occurs the                 } *                 if(Widthintiles = = 0) $Widthintiles =columns.length;Panax NotoginsengColumn = 0; -                  while(Column <widthintiles) the_data.push (UINT (columns[column++));//press the whole column into the _data +             } A              the             //pre-process The map data if it ' s auto-tiled +             varI:uint; -Totaltiles = widthintiles*Heightintiles; $             if(Auto >OFF) $             { -_startingindex = 1; -Drawindex = 1; theCollideindex = 1; -i = 0;Wuyi                  while(I <totaltiles) theAutotile (i++); -             } Wu              -             //figuring out the size of the tiles About_tiles = Flxg.addbitmap (tilegraphic);//Loading Images $_tilewidth =Tilewidth; -             if(_tilewidth = = 0) -_tilewidth = _tiles.height;//function parameter does not work -_tileheight =Tileheight; A             if(_tileheight = = 0) +_tileheight = _tilewidth;//function parameter does not work the              -             //Create some tile objects, left to do overlapping checks (each one) $i = 0; the             varL:uint = (_tiles.width/_tilewidth) * (_tiles.height/_tileheight); the             if(Auto >OFF) thel++; the_tileobjects =NewArray (l); -             varAc:uint; in              while(I <l) the             { the_tileobjects[i] =NewFlxtile ( This, I,_tilewidth,_tileheight, (i >= drawindex), (i >= collideindex)?allowcollisions:none); Abouti++; the             } the              the             //objects created for debug requirements +_debugtilenotsolid =Makedebugtile (flxg.blue); -_debugtilepartial =Makedebugtile (flxg.pink); the_debugtilesolid =Makedebugtile (flxg.green);Bayi_debugrect =NewRectangle (0,0, _tilewidth,_tileheight); the              the             //Create a map -width = widthintiles*_tilewidth; -Height = heightintiles*_tileheight; the_rects =NewArray (totaltiles); thei = 0; the              while(I <totaltiles) theUpdatetile (i++);//Refresh -  the             return  This; the}

Well, know what is mapdata, in fact, is the use of "," and "\ n" Partition of the ordinary map data only, the basic can be used. There are other parameters that are also clearer. It can be said, know Loadmap () basic can use this class, but it also has a lot of advanced features, next time see it.

The code in the gamestate is changed so that the remainder can be displayed.

1          Public functiongamestate ()2         {3             varData:array = [2, 2, 2, 1, 1, 1, 2,42, 0, 2, 1, 1, 2, 0,52, 2, 2, 1, 2, 0, 0];6Map =NewFlxtilemap ();7Map.loadmap (Flxtilemap.arraytocsv (data, 7), Imgtile, 20,flxtilemap.off,0,0,1);8 Add (map);9}

Code Address: Https://github.com/quanjp/LearningFlixel/tree/master/002loadMap

Flixel Learning Note 002 Loading map (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.