|
|
|
 |
Reply From: |
njamster |
but I don’t understand why it’s not accepting TileMap: 1243 as an argument… that is what the node is called when I print it out.
When you print something out, it’s a String. So if you would like to pass the text that was printed as an argument to a function, you’d put it in quotation marks: “TileMap:(1234)”. However, remove_child
expects a Node as an argument, not a String! So what you actually should do (if your TileMap is called “TileMap”) is this:
var child = get_node("DissappearingPlatforms").get_node("TileMap")
get_node("DissappearingPlatforms").remove_child(child)
I do not understand where it is expecting a parenthesis or a comma.
At the end of the line. It simply checks if each parenthesis is closed later. Which is not the case in your code: remove_child _(_ TileMap: _(_ 1243 _)_
will I be able to simply add the child node back in as it was previously, after I remove it?
As long as you keep a reference to the node around (like the variable child
in my example above` you can add it back to the tree at any time, yes:
var child = get_node("DissappearingPlatforms").get_node("TileMap")
get_node("DissappearingPlatforms").remove_child(child)
# do something else, let time pass...
get_node("DissappearingPlatforms").add_child(child)
Hey, thanks for your help again!
I unsderstand almost everything, but I may given the wrong information.
DissappearingPlatforms is a tilemap itself, and has no children. DissappearingPlatforms is a child of the root node, which is StageOne. The script you are seeing above is my StageOne script. Would what you just said still work? I am going to try it out now
eviking | 2020-04-29 17:55
Well, if DissappearingPlatforms does not have any children, you obviously cannot remove them.
What you can do though is removing the TileMap itself:
var tilemap = get_node("DissappearingPlatforms")
remove_child(tilemap)
# do something else, let time pass...
add_child(tilemap)
If your goal is to only remove certain tiles, you cannot do it this way (as tiles are not individual nodes, but a set of three numbers the TileMap-node interpretes). However, you can reset a cell of the TileMap back to “No-Tile” using this:
get_node("DissappearingPlatforms").set_cellv(x, y, -1)
where x
and y
are the cell’s indices in horizontal and vertical direction.
njamster | 2020-04-29 18:07
Perfect, yes at this point I am fine with removing the Tilemap itself and then just adding it back in.
Handy stuff for resetting the tilemap back to No-Tile. That will definitely be useful in future projects. Thanks again!
eviking | 2020-04-29 18:44