Topic was automatically imported from the old Question2Answer platform.
Asked By
szccornish
extends Node2D
onready var tween = $Bar_Tween
onready var Bar = $Bar_BG
var Revealpos = Vector2(112,176)
var Hidepos = Vector2(112,208)
func _on_Bar_UI_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton && Bar.position(112,176): <---- im i right writing this?
if event.is_pressed() :
tween.interpolate_property(Bar, ‘position’, Revealpos, Hidepos,1.0,Tween.TRANS_LINEAR, Tween.EASE_IN_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.
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)):
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 _on_Bar_UI_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton :
if event.is_pressed() && bar_BG.position.is_equal_approx(Vector2(112,176)) :
tween.interpolate_property(Bar, ‘position’, Revealpos, Hidepos,1.0,Tween.TRANS_LINEAR, Tween.EASE_IN_OUT )
tween.start()
if event.is_pressed() && bar_BG.position.is_equal_approx(Vector2(112,208)) :
tween.interpolate_property(Bar, ‘position’, Hidepos, Revealpos,1.0,Tween.TRANS_LINEAR, Tween.EASE_IN_OUT )
tween.start()