Inventory Flickering by Mouse Movement

Godot Version

4.6 Stable

Question

I am currently working on a point and click adventure and I'm working on the inventory. The plan is to make it slide up from the bottom of the screen and slide back down whenever your mouse is close to the bottom of the screen. So far it works how I want it, but for some reason the icon (Sprite2D) starts flickering at random when I move my mouse around

After a lot of testing I discovered it only happens when my mouse is moving over the HBoxcontainer I made to hold the sprites for the items. When I delete the container this does not happen. It’s very strange since my code is small and doesn’t involve the Container.

extends Control

@onreadyonready var mouse_position := get_global_mouse_posi@onreadyion()
@onready var inventory: Node2D = $Inventory
@onready var bag: Button = %Bag

func _ready() → void:
inventory.visible = false

func _on_area_2d_mouse_entered() → void:
inventory.visible = true
inventory.position.y = inventory.position.y - 160
print(inventory.position)

func _on_area_2d_mouse_exited() → void:
inventory.position.y = inventory.position.y + 160
inventory.visible = false
print(inventory.position)

Here is the scene of the UI. The buttons are there just for testing purposes, it still happens even when the Container is empty. Anyone know why this happens?

Please format your code by using the image toolbar button or pressing Ctrl+E.

If this line is actually in your code, it is possibly the problem:

@onreadyonready var mouse_position := get_global_mouse_posi@onreadyion()

Oh! No that is definitely not my code! I’m sorry, I have no clue why it pasted that way, but here is my actual code

Your gif doesn’t show the behavior too well. When exactly is the sprite “disappearing”? Move the mouse slowly and enable debug display of collision shapes in Debug > Visible Collision Shapes.

1 Like
  1. Your mouse_position variable does nothing.
  2. Your bag variable does nothing.
  3. The reason it’s blinking is because you’re moving it on mouseover and causing it to enter and exit over and over in an infinite loop.

Yeah, those variables are left over when I was trying some stuff, but that solved it! I didn’t realize the container and the buttons had a mouse filter property. Thanks so much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.