|
|
|
|
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