Make a drawing with tiles in an intro animation?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By megsmarie

So in my intro, I have a stick come in and draw in the dirt (tile map). I used the AnimationPlayer node as a child of the Sprite node for the stick and it comes in and out exactly how I want it to. But I have no idea how to put the tile for the darker dirt path made by the stick that would follow behind it. I tried having the tile as a Sprite attached to AnimationPlayer as well, but 1) it was like 30 different Sprites so that should appear one by one in the key frames as I needed them to behind the stick and 2) that wouldn’t even work because all of the tile sprites stayed visible throughout the whole animation, even at the beginning where they had no key frame. Either that, or the sprite just follows the stick around instead of staying in its location on the scene.

There has to be an easier way to just plop things into the animation? Is there a way I can draw it on a separate TileMap node and reveal it slowly through the animation?

Thanks for any pointers in advance

:bust_in_silhouette: Reply From: estebanmolca

I don’t understand very well how the implementation is but there are several ways, Tilemap has several functions, including creating an ingame tile, example:

$ TileMap.set_cellv (tilemap.world_to_map (get_global_mouse_position ()), 0)

In this example I use the mouse position to create tiles while I move it, look at the world_to_map (Vector2) function, what it does is pass the world coordinates (Increase by one for each pixel) to the tilemap coordinates (increase by one by each tile). The integer at the end indicates the tile id, which are unique for each tile in the tilemap. Using -1 removes the tile in position. If there is another tile already drawn it is replaced.

What I would do is include a Position2D node as the child of your animated sprite (or use the sprite position), at the tip where it draws. Then I would use its position (Your global position) in the set_cellv () function to draw the tiles as it moves. Example pseudocode:

func _process:
   if animation_is_start:
      $TileMap.set_cellv ( $TileMap.world_to_map($Sprite/Tip.global_position), 0)

Thanks so much for helping.

I’ve tried like 50 different variations of what you suggested mixed with a lot of googling/redditing and still nothing.

Right now, I think I’m close - so I landed on entering the code into the TileMap script directly and calling the $Sprite’s location, so that I could specify when the sprite is at a certain location (during the animation), tile map paints a tile there.

extends TileMap

func _ready ():
$Sprite.get_position_in_parent()
if $Sprite.set_position ( 404.29, 340.293):
TileMap.set_cellv(404.29, 340.293, get_tileset()

The values are from the first position of the sprite as it shows in the Inspector where I want the tile painted. Alternatively, I had tried using the grid (8,1) coordinates and it had no clue what to do with those.

The error I keep getting now is “Non-static function “set_cellv” can only be called from an instance”.

I don’t understand, I’m writing in TileMap, where is the confusion for the script to use set_cellv coming from? Should I try calling the scene tree??

I also can’t find anything anywhere about how to determine which tile I want placed. I had previously in the last line “get_tileset(_find_tile_name(“Dirtline”))” and it was returning the error that _find_tile_name is not in this class, but I’m writing in extends TileMap.

;_;

megsmarie | 2020-10-11 04:18