Created
September 5, 2021 22:42
-
-
Save sjvnnings/6b54a962f4c72758b182c49f655ed4e8 to your computer and use it in GitHub Desktop.
A Simple JRPG-style cursor script in Godot. To use, just set the menu_parent_path property in the editor to the container your menu options are stored in.
var menu_position = menu_item.global_position
var menu_size = menu_item.size
global_position = Vector2(menu_position.x, menu_position.y + (menu_size.y / 2.0)) - (size / 2.0) - cursor_offset
You need to change your position variable name since position is referencing the current position of your pointer which changes with every iteration of _process so it keeps moving away as the number gets bigger. At least, that's what was wrong with mine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`extends TextureRect
@export var menu_parent_path : NodePath
@export var cursor_offset : Vector2
@onready var menu_parent := get_node(menu_parent_path)
var cursor_index : int = 0
func _process(delta):
var input := Vector2.ZERO
if Input.is_action_just_pressed("up"):
input.y -= 1
if Input.is_action_just_pressed("down"):
input.y += 1
if Input.is_action_just_pressed("right"):
input.x += 1
if Input.is_action_just_pressed("left"):
input.x -= 1
func get_menu_item_at_index(index : int) -> Control:
if menu_parent == null:
return null
if index >= menu_parent.get_child_count() or index < 0:
return null
return menu_parent.get_child(index) as Control
func set_cursor_from_index(index : int) -> void:
var menu_item := get_menu_item_at_index(index)
Here is the script for the "Menu Cursor" Scene.
Here is a screenshot of the problem:
In this screenshot, the cursor should be appearing at the red circle, however its position is sent far off the camera. (Position Circled in red)