Sprite position Error

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby

Im getting an error saying that there is no exsiting function position in base Sprite
I trying to make my level select with a sprite to show what you are selecting by moving left to right acrross the stages.Using Godot 3.0

extends Node
var index=0
func _ready():
set_process_input(true)
func _input(event):
if event.is_action("ui_left") && event.is_pressed() && !event.is_echo():
	if index!=0:
		index-=1
		var x=get_node("Select").position().x-200
		var y=get_node("Select").position().y
		get_node("Select").position(Vector2(x,y))
if event.is_action("ui_right") && event.is_pressed() && !event.is_echo():
	if index!=4:
		index+=1
		var x=get_node("Select").position().x+200
		var y=get_node("Select").position().y
		get_node("Select").position(Vector2(x,y))
if event.is_action("confirm") && event.is_pressed() && !event.is_echo():
	if index==0:
		print("stage1")
	if index==1:
		print("stage2")
	if index==2:
		print("stage3")
	if index==3:
		print("stage4")
	if index==4:
		print("stage5")
:bust_in_silhouette: Reply From: anllucah

try something like:

var pos = get_node("Select").get_position()
pos.x -= 200
get_node("Select").set_position(pos)

Note, this could be written as:

$Select.position.x -= 200

kidscancode | 2018-03-01 15:00

:bust_in_silhouette: Reply From: mollusca

Sprite doesn’t have a position function but it does have a position member variable. So just change .position() to .position.

:bust_in_silhouette: Reply From: Guilherme Furst

positionis a member variable of Node2d (or perhaps CanvasItem, can’t find it to be honest)

But instead of position you should be checking methods, get_pos() or get_global_pos().
And to change them set_pos(Vector2) or translate(Vector2).
Where as, translate just offsets from its current position.

This is incorrect. get_pos() and get_global_pos() don’t exist in Godot 3.0.

And in 3.0, assigning to Node2D.position or Node2D.global_position is the preferred method.

kidscancode | 2018-03-01 14:59