HIde and reveal a Inventory BAR with a tween

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

i have been trying to make my bar go UP and DOWN (Hide and reveal) using a tween, but nothing happens. i wanted it when i click the bar with my left mouse button, its toggled up and down. do you have any idea whats wrong with my code? or did i miss something.

extends Node2D

onready var tween = get_node(“Bar_Tween”)

func _ready():

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

if Input.is_mouse_button_pressed(BUTTON_LEFT):
	tween.interpolate_property($Bar_BG, "rect_position", Revealpos, Hidepos,1.0,Tween.TRANS_LINEAR, Tween.EASE_IN_OUT )
	tween.start()
:bust_in_silhouette: Reply From: Ertain

Try putting the code into an _input() function:

_input(event):
     if Input.is_mouse_button_pressed(BUTTON_LEFT):
         tween.interpolate_property($Bar_BG, "rect_position", Revealpos, Hideposs,1.0,Tween.TRANS_LINEAR, Tween.EASE_IN_OUT )
tween.start()

If that falls, try the _process() function.

hai i found a way… but its only go down… then wont go up anymore in the second click… do you know whats wrong with my code?

extends Node2D

onready var tween = $Bar_Tween
onready var Bar = $Bar_BG
onready var bar_BG = $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 :
if event.is_pressed() && bar_BG.position.is_equal_approx(Revealpos) :
tween.interpolate_property(Bar, ‘position’, Revealpos, Hidepos,1.0,Tween.TRANS_LINEAR, Tween.EASE_IN_OUT )
tween.start()
if event is InputEventMouseButton :
if event.is_pressed() && bar_BG.position.is_equal_approx(Hidepos) :
tween.interpolate_property(Bar, ‘position’, Hidepos, Revealpos,1.0,Tween.TRANS_LINEAR, Tween.EASE_IN_OUT )
tween.start()

szccornish | 2020-12-22 02:06

Could you fix the formatting?

Ertain | 2020-12-22 08:01