CELL_SIZE is multiplied but mask.positon is added. Why?

I wonder why mask.position was added to mask.map_to_world(cell) and random_offset, while before we've multiplied CELL_SIZE by cell + random_offset. Why the difference?

  • godoterfr replied


    In red, the position (0, 0)
    In blue, the offset (64, 64) of the TileMap node named Mask.
    In green, the 1st cell of the mask

    mask.position = (64, 64) <= offset of the Mask
    cell = (4, 3) <=  the 1st cell of the mask (coordinates of the tile)
    mask.map_to_world = (512, 384) <= the 1st cell of the mask * cell_size(128, 128)

    Returns the local position of the top left corner of the cell corresponding to the given tilemap (grid-based) coordinates.

    We will therefore put a rock in on this position added with an offset :

    rock.position = mask.position + mask.map_to_world(cell) + random_offset

    Substitution steps :
    rock.position = mask.position + mask.map_to_world(cell) + random_offset
    rock.position = (64, 64) + mask.map_to_world(4, 3) + random_offset
    rock.position = (64, 64) + (512, 384) + random_offset
    rock.position = (576, 448) + random_offset

    4 loves
  • Nathan Lovato replied

    As mentioned in the lesson:

    We first account for the Mask node’s position, as we moved it in the editor.

    We had to move the Mask node a bit for the generated rocks to be placed in the middle of grass tiles, so we need to account for this offset in our code.