Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Tomi |
As I can see, many people have asked this question here, but the answers aren’t work in my code, because it doesn’t know “texture” property.
I would like set the position of the enemy objects based on their sprites. E.g. let an enemy be created at -128 and (get_viewport_rect().size).y-256 if it has 128*256 pixels dimensions. So, let it be outside the screen, at its left corner.
I tried texture.get_size() and similar commands, but it never liked “texture” property.
Here is my piece of code:
func _startenemy():
var eninst=preload("res://monster1.tscn")
var itssprite: Sprite=get_node("res://monster.png")
var anenemy=eninst.instance()
get_parent().add_child(anenemy)
anenemy.position.x=-itssprite.texture.get_size.x
anenemy.position.y=(get_viewport_rect().size).y-itssprite.texture.get_size.y