Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Jambers | |
Old Version | Published before Godot 3 was released. |
I am trying to spawn an object “yellow_sprite” at the location (0,0) when I press a button “yellow_spawn_button”. Instead of spawning at (0,0), the object is spawning on top of its parent.
Code:
extends Node2D
var yellow_sprite = preload("yellow_sprite.tscn")
var yellow_sprite_location = Vector2(0,0)
func _on_button_pressed(): "Spawn a yellow pixel when the yellow button is pressed"
var yellow_sprite_create = yellow_sprite.instance()
yellow_sprite_location=Vector2(0,0)
yellow_sprite_create.set_pos(yellow_sprite_location)
get_node("pixel").add_child(yellow_sprite_create)
func _ready():
get_node("yellow_spawn_button").connect("pressed",self,"_on_button_pressed")