Why isn't my joystick's 2nd circle visible when it's a child node?

  • Thread starter Thread starter Darkmisc
  • Start date Start date
AI Thread Summary
The issue with the joystick's InnerCircle sprite not being visible when used as a child node in Player.tscn, despite functioning correctly, is likely related to visibility and hierarchy settings. The InnerCircle is confirmed to be visible in the editor, but it may be obscured by other nodes or not rendered correctly due to its position in the scene tree. Suggestions include verifying the visibility properties of both the joystick and InnerCircle, checking their Z-index and layer settings, and ensuring that the parent-child hierarchy is correctly configured. Additionally, focus settings may play a role in visibility, as certain nodes may require focus to render properly. Troubleshooting these aspects should help resolve the visibility issue.
Darkmisc
Messages
222
Reaction score
31
TL;DR Summary
My Godot game uses a touchscreen joystick comprising of two circles. One is the touchscreen area. The other is a smaller circle to show where the player is pressing. The smaller circle is visible when I run the joystick scene on its own, but not visible when the joystick is a child node.
Hi everyone

I'm using this code for a touchscreen joystick in my Godot game:
[CODE lang="python" title="joystick"]
extends CanvasLayer

var move_vector = Vector2(0, 0)
var joystick_active = false

func _input(event):
if event is InputEventScreenTouch or event is InputEventScreenDrag:
if $TouchScreenButton.is_pressed():
move_vector = calculate_move_vector(event.position)
joystick_active = true

$InnerCircle.position = event.position
$InnerCircle.visible = true

if event is InputEventScreenTouch:
if event.pressed == false:
joystick_active = false
Global.move_vector=Vector2(0,0)
$InnerCircle.visible = false


func _physics_process(_delta):
if joystick_active:
Global.move_vector = move_vector
emit_signal("use_move_vector", move_vector)

func calculate_move_vector(event_position):
var texture_center = $TouchScreenButton.position + Vector2(100,600)
return (event_position - texture_center).normalized()
[/CODE]

The code works for controlling the player, but the InnerCircle sprite is only visible when I run the joystick scene on its own. When I run it as a child node of Player.tscn, InnerCircle doesn't appear, although the joystick still works fine.
1695774452337.png


InnerCircle (the black dot) is visible in the editor, but not when I run Player.tscn.

1695774502805.png


The same applies when I run Player.tscn as a child node of Level.tscn.

Does anyone know why this is happening? I'm stuck for ideas. I've tried making sure the joystick ("Node2D") is on top, but it's in a canvas layer, so nothing should be blocking it anyway. Thanks
 
Technology news on Phys.org
Does the widget need focus to show the player dot?

Focus is when a widget is somehow selected by the user.

  • Checking visibility properties -- are both components set to visible
  • Verifying layer and Z-index settings -- check if the inner circle isn't hiding behind some component
  • Ensuring correct scale and position.
  • Checking collision shapes.
  • Reviewing the parent-child hierarchy.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top