0 votes

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")
in Engine by (395 points)

3 Answers

+1 vote

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

by (1,554 points)
–2 votes

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.

by (59 points)

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.

+1 vote

try something like:

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

Note, this could be written as:

$Select.position.x -= 200
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.