This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

extends Node2D

onready var tween = $BarTween
onready var Bar = $Bar
BG

var Revealpos = Vector2(112,176)
var Hidepos = Vector2(112,208)

func onBarUIinputevent(viewport, event, shapeidx):
if event is InputEventMouseButton && Bar.position(112,176): <---- im i right writing this?
if event.ispressed() :
tween.interpolate
property(Bar, 'position', Revealpos, Hidepos,1.0,Tween.TRANSLINEAR, Tween.EASEIN_OUT )
tween.start()

the debugger write a "invalid call. Nonexistent function 'position in base 'Sprite'."

im trying to hide and reveal (Down n Up) a sprite box.

Godot version 3.2.1
in Engine by (69 points)

1 Answer

+1 vote
Best answer

position is a Property, not a Function. You're treating it like a function. With a property, you can set or get the value by simply reference in the property name.

So, to set it: Bar.position = Vector2(10,10)
To get the current value: var pos = Bar.position

It looks like you're trying to verify that the mouse button is pressed and the position of the sprite is very near a specific position. In that case, you might want to try something like:

if event is InputEventMouseButton && Bar.position.is_equal_approx(Vector2(112,176)):
by (22,704 points)
selected by

thank that is exactly what i was looking for.. but i have a little problem.. when it go down. it wont go up anymore.

func onBarUIinputevent(viewport, event, shapeidx):
if event is InputEventMouseButton :
if event.ispressed() && barBG.position.isequalapprox(Vector2(112,176)) :
tween.interpolateproperty(Bar, 'position', Revealpos, Hidepos,1.0,Tween.TRANSLINEAR, Tween.EASEINOUT )
tween.start()
if event.ispressed() && barBG.position.isequalapprox(Vector2(112,208)) :
tween.interpolateproperty(Bar, 'position', Hidepos, Revealpos,1.0,Tween.TRANSLINEAR, Tween.EASEINOUT )
tween.start()

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 Frequently asked questions and 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 [email protected] with your username.