crystal-bit / godot-game-template

Generic template for Godot games
MIT License
598 stars 47 forks source link

Bug+Fix: Transitions scene blocks _input even when it is translucent #67

Closed Iftahh closed 2 years ago

Iftahh commented 2 years ago

The Bug:

Even when the scene transitions completes, the Transitions scene remains in the tree, but it is invisible (since ColorRect is animated to be alpha=0).

However, it still blocks _input events. ie. if there is a button where the progress bar is located, it is impossible to click the button (or hover it), even when the progress bar is invisible.


The fix is simple, and I think as a bonus side affect it will probably (very slightly) improve performance (perhaps avoiding some needless process() and rendering of transparent textures).

The Fix:

Simply hide the ColorRect when its not needed:

transitions.gd (modified lines highlighted with <<<<<<<, unchanged functions omitted for brevity)


onready var background = $ColorRect

func _ready():
    background.hide()      # <<<<<<<

# Tells if transition is currently displayed
func is_displayed() -> bool:
        return background.visible          # <<<<<<<<
        #
        # I don't think these two lines are necessary, but maybe I'm missing something?
    # var is_screen_black = background.modulate.a == 1
    # return anim.is_playing() or is_screen_black

# appear
func fade_in(params = {}):
    background.show()  # <<<<<<<<
    progress.hide()
    if params and params.get('show_progress_bar') != null:
        if params.get('show_progress_bar') == true:
            progress.show()
    anim.play("transition-in")

func _on_fade_out_finished(cur_anim):
    if cur_anim == "transition-out":
        progress.bar.value = 0
    background.hide()         # <<<<<<<<<

# rest of file is unchanged