Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | rubendw03 |
I tried to spawn objects using this method:
https://www.reddit.com/r/godot/comments/d62laz/spawning_on_tiles/
But the objects are invisible. When i let the objects print their position and check the remote scene tree they get spawned correctly but just aren’t visible. When I run the game with visible collision shapes the collision shapes of the objects do not show neither.
here is the script that spawns the objects:
extends Node2D
onready var plants = $Plants
onready var tileMap = $TileMap
export(PackedScene) var Plant
var rng = RandomNumberGenerator.new()
func _ready():
plant()
plant()
func _on_Plant_popped():
plant()
func plant():
randomize()
var plant = Plant.instance()
plants.call_deferred("add_child", plant)
var spawnpoints = tileMap.get_used_cells_by_id(1)
plant.position = (tileMap.cell_size) * spawnpoints[rng.randi_range(0, spawnpoints.size()-1)]
and here is the object’s code:
extends Area2D
onready var animationPlayer = $AnimationPlayer
onready var popTimer = $PopTimer
onready var berryShape = $BerryShape
var FLOOR = Vector2(0, -1)
signal popped()
func _ready():
animationPlayer.play("Idle")
connect("popped", get_node("/root/TestWorld"), "_on_Plant_popped")
connect("popped", get_node("/root/TestWorld/GUI/HungryBar/MarginContainer/TextureProgress"), "_on_Plant_popped")
func _on_Plant_body_entered(body):
if body.get_name() == "HummingBird":
if body.state == body.ATTACK:
animationPlayer.play("Pop")
berryShape.set_deferred("disabled", true)
popTimer.start()
emit_signal("popped")
func _on_PopTimer_timeout():
queue_free()