1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Implementing custom tiles (not blobs) at the map loaders

Discussion in 'Modding [KAG]' started by 8x, Jul 19, 2016.

Tags:
  1. 8x

    8x Elimination Et Choix Traduisant la Realité Forum Moderator Staff Alumni Tester
    1. The Young Blood Collective - [YB]

    Messages:
    1,325
    For custom tiles to be in the map loaders you need to touch only World.png and CustomBlocks.as. Notice this tutorial is for implementing custom tiles a the map loaders. For buildable tiles via Builder Menu I can't tell but hopefully somebody will post it here.

    Once you've drawn your tile and put it inside World.png (preferably after the frame 256), at CustomBlocks.as you have to make these 3 steps:

    First step: it lists the new custom tiles and it says to the loaders something like "in World.png, at the frame x there is a new tile called tile_named_whatever". I don't know if it's needed to call everything tile_whatever_here, but I use it.
    Code:
    namespace CMap
    {
        enum CustomTiles
        {
      
      
            // 256 on line
            tile_sandbag_1 = 258,
            tile_sandbag_2 = 259,
            tile_sandbag_3 = 260,
      
            tile_wooden_box_1 = 262,
            tile_wooden_box_2 = 263,
            tile_wooden_box_3 = 264 // the last line in the enum has no coma in the end
    
    
    
        };
    };
    In the second step you specify which colour you'll be using in your maps for the loader to recognize it on the pngs. It's (Transparency, R, G, B). Give your colours a similar name to their specific tiles for a faster understanding.

    Code:
    const SColor color_sandbag_1(255, 127, 100, 0);
    const SColor color_sandbag_2(255, 127, 100, 30);
    const SColor color_sandbag_3(255, 127, 100, 60);
    
    In the third step you say something like "when you find x colour, place x tile; x tile will have this qualities".
    Here comes the best, you can apply different qualities to each custom tile , these are called Tile Flags and can be seen at Enums.txt in the manual folder:
    Code:
    Tile::TileFlags
        SPARE_0
        SOLID
        BACKGROUND
        LADDER // didn't get this one to work
        LIGHT_PASSES
        WATER_PASSES
        FLAMMABLE
        PLATFORM // didn't try this one
        LIGHT_SOURCE
        MIRROR
        FLIP
        ROTATE // Mirror flip and rotate affect only the sprite
        COLLISION
        SPARE_2
        SPARE_3
        SPARE_4
    You can combine these tile flags to create your tiles. In general, except for sky, vanilla tiles have "LIGHT_SOURCE" not enabled, (TR does so you can see all the map, there's no darkness). By default, the custom tiles will have "LIGHT_SOURCE" and "LIGHT_PASSES" enabled. You have to remove them if you want it to be under the shader with a RemoveTileFlag line. An example of a solid block, that doesn't emit light:
    Code:
    else if (pixel == color_wood_block_1_left){
            map.SetTile(offset, CMap::tile_wood_block_1_left );
            map.RemoveTileFlag( offset, Tile::LIGHT_SOURCE );
            map.AddTileFlag( offset, Tile::SOLID | Tile::COLLISION );
    }
    
    Vanilla use special spawn and on-the-go tileflags modifications (for instance if you put backwall on a stone block it will directly become different visually, or a column of wooden blocks will have each one mirrored regarding the one below or above), but that's something more complex and I can't really do much. I can't help with building them ingame.

    If you want a tile to be solid, you have to put both SOLID and COLLISION. Usually solid blocks are not LIGHT_SOURCE, but I use it for decoration.
    If you want a background tile, use BACKGROUND and, i guess, LIGHT_PASSES (not from the back to the front, but from left to right/up to down) and WATER_PASSES.
    If you want a frontground non solid tile, simply don't put BACKGROUND.

    Examples from The Waste Kind mod:

    View attachment 52659

    View attachment 52660
    These blue and greenish containters are SOLID and COLLISION, but also LIGHT_SOURCE as I want them to be visible. The snow doesn't have BACKGROUND, SOLID or COLLISION tileflags, so it's on the frontground and doesn't collide, like the shadowed hand-rail on the first image. The columns and Z metal bars are just BACKGROUND and LIGHTPASSES.
    Check the files I attach too for more info.
     

    Attached Files:

    Blubahub, FunATuns, jonipro and 5 others like this.
  2. jonipro

    jonipro Haxor Tester
    1. Terracraft's Servers

    Messages:
    75