Hello Guest

Author Topic: 'Fill' method for Tilemap  (Read 3232 times)

0 Members and 1 Guest are viewing this topic.


  • Member
  • Posts: 1
    • View Profile
'Fill' method for Tilemap
« on: February 26, 2016, 05:31:53 PM »
For creating top-down games, the user may want to fill the scene with 1 texture.
The first thing I searched for when wanting this was myTilemap.Fill(...), and obviously that didn't exist. Not sure how active this forum is, or if this does exist already and I'm just dumb.
Code: [Select]
        public void Fill(int tileIndex) {
          // I know, right. No comments, or exception handling.. Shame on me!
          for (int dy = 0; dy < this.TileRows; dy++) {
            for (int dx = 0; dx < this.TileColumns; dx++) {
              this.SetTile(dx, dy, 0);



  • Member
  • Posts: 8
    • View Profile
Re: 'Fill' method for Tilemap
« Reply #1 on: February 27, 2016, 12:01:46 PM »
This forum isnt used much lately. If you really want to join a more active place to talk/make questions about otter and gamedev in general. You can join everyone on Slack http://otter2d.com/slack.php
In regards to the fill thing. Tilemap does have a method for this it looks like. Called 'SetRect'
Code: [Select]
        /// <summary>
        /// Set a rectangle of tiles to a tile defined by an index.
        /// </summary>
        /// <param name="tileX">The X position of the rectangle to change.</param>
        /// <param name="tileY">The Y position of the rectangle to change.</param>
        /// <param name="tileWidth">The width of tiles to change.</param>
        /// <param name="tileHeight">The height of tiles to change.</param>
        /// <param name="tileIndex">The index of the tile to change the tiles to.</param>
        /// <param name="layer">The layer to place the tiles on.</param>
        public void SetRect(int tileX, int tileY, int tileWidth, int tileHeight, int tileIndex, string layer = "") {
            for (int xx = tileX; xx < tileX + tileWidth; xx++) {
                for (int yy = tileY; yy < tileY + tileHeight; yy++) {
                    SetTile(xx, yy, tileIndex, layer);


  • Administrator
  • Member
  • Posts: 259
    • View Profile
Re: 'Fill' method for Tilemap
« Reply #2 on: February 29, 2016, 12:23:03 PM »
Yup! Yeah it seems that the forums have been replaced with Slack, so I might make that more apparent on here somewhere.