0 votes

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 = getnode("BarTween")

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()
Godot version 3.2.1
in Engine by (69 points)

1 Answer

0 votes

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.

by (3,144 points)

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 = $BarTween
onready var Bar = $Bar
BG
onready var barBG = $BarBG

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

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

Could you fix the formatting?

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.