Hello Guest

Author Topic: Random Paint Tiles don't flip on TileMap  (Read 3965 times)

subliminalman

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Random Paint Tiles don't flip on TileMap
« on: October 20, 2013, 11:18:24 pm »
Whenever I use the random brush the horizontal flip and/or vertical flip flags don't actually flip any of the sprites.

I am currently on version 2.2.3

If this could be added then it would speed up my process sooo much!


Thank you!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Random Paint Tiles don't flip on TileMap
« Reply #1 on: October 21, 2013, 11:36:24 am »
That was never done because its a tricky one - what do you randomize? Whether its flipped or not? I can think of uses for all the different combinations of this, and the problem is when we discussed it, we couldn't find a nice way to present it. The current behaviour seemed the least problematic of the other options.

Its really easy to patch in though. Look for these lines in tk2dTileMapSceneGUI.cs and add the lines in bold -

      if (tk2dTileMapToolbar.mainMode == tk2dTileMapToolbar.MainMode.BrushRandom) {
         int gridWidth = 1 + rectX2 - rectX1;
         int gridHeight = 1 + rectY2 - rectY1;
         workBrush.tiles = new tk2dSparseTile[gridWidth * gridHeight];

         var rng = new System.Random(randomSeed + cursorY * tileMap.width + cursorX);

         int idx = 0;
         for (int y = 0; y < gridHeight; ++y) {
            int thisRowXOffset = ((y & 1) == 1) ? xoffset : 0;
            for (int x = 0; x < gridWidth; ++x) {
               int spriteId = srcTiles[rng.Next(srcTiles.Length)].spriteId;

               if (rot90)
                  tk2dRuntime.TileMap.BuilderUtil.SetRawTileFlag(ref spriteId, tk2dTileFlags.Rot90, true);
               if (flipH)
                  tk2dRuntime.TileMap.BuilderUtil.InvertRawTileFlag(ref spriteId, tk2dTileFlags.FlipX);
               if (flipV)
                  tk2dRuntime.TileMap.BuilderUtil.InvertRawTileFlag(ref spriteId, tk2dTileFlags.FlipY);


               workBrush.tiles[idx++] = new tk2dSparseTile(
                  rectX1 + x + thisRowXOffset, rectY1 + y, editorData.layer, spriteId);
            }
         }
      }

subliminalman

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Random Paint Tiles don't flip on TileMap
« Reply #2 on: October 22, 2013, 08:04:44 am »
Perfect! Exactly the solution that I was needing! This will help speed up our level creation process so much!

Thank you.

I can understand the difficulty on the implementation on whether or not the user wants each tile randomly flipped or all selected tiles in the same direction. The only thing I can think of would be a toggle button that only comes up with the random mode selected but that may not be the best solution.


Thank you again!