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

  • Thread starter Darkmisc
  • Start date
  • #1
Darkmisc
204
27
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:
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()

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
  • #2
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.
 
  • Like
Likes Darkmisc

1. Why is the 2nd circle of my joystick not visible when it's a child node?

The most likely reason for this is that the second circle of the joystick is either being hidden by another element or is not properly positioned within the parent node. Check the CSS styles for both the parent and child nodes to ensure that there are no conflicts or errors.

2. How can I make the 2nd circle of my joystick visible as a child node?

To make the second circle of the joystick visible as a child node, you will need to adjust the positioning and/or z-index of the circle within the parent node. You may also need to add specific CSS styles to ensure that the circle is not being hidden by other elements.

3. Could the issue with the 2nd circle of my joystick not being visible be related to the code?

It is possible that the issue with the second circle of the joystick not being visible is related to the code. Double check the code for any errors or typos, and make sure that the circle is properly defined as a child node in the HTML markup.

4. Is there a specific reason why the 2nd circle of my joystick is not showing up as a child node?

There may be several reasons why the second circle of the joystick is not showing up as a child node. Some possible reasons include incorrect CSS styles, coding errors, or conflicts with other elements on the page. It is important to carefully examine the code and troubleshoot to determine the exact cause.

5. Can I use a different method to make the 2nd circle of my joystick visible as a child node?

Yes, there may be alternative methods to make the second circle of the joystick visible as a child node. This could include using different CSS styles or adjusting the positioning of the circle within the parent node. Experiment with different approaches to see what works best for your specific situation.

Similar threads

  • Programming and Computer Science
Replies
4
Views
947
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
5
Views
993
Back
Top