In your code BOMB
is a scene you've loaded from a file. This means it is a PackedScene
object. A PackedScene contains all the information about what nodes, data, etc. make up your object.
We use the PackedScene's instance()
function to actually create all of those nodes. You are doing this when you do the following:
var bomb = BOMB.instance()
get_parent().add_child(bomb)
This is fine - you've created an instance of BOMB
and called it bomb
and added it to the tree. However, on the next line, you try do to these things:
BOMB.position = $Position2D.global_position
var BOMB = BOMB.instance()
World.add_child(BOMB)
This is problem because
1) BOMB
doesn't have a position - it's not a node, it's the PackedScene.
2) var BOMB = BOMB.instance()
- you're deleting your PackedScene by replacing it with an instance.
You're already doing the right thing when you create the instance called bomb
, so just set bomb.position
to what you want.
You also have some strange things going on with your indentation under the is_action_just_pressed("place bomb")
. Why do you have it there twice?