Port to Godot 4

This commit is contained in:
Just 2023-01-26 21:04:34 -08:00
parent 4ff80824ce
commit 78f9147c25
18 changed files with 227 additions and 174 deletions

2
.gitignore vendored
View file

@ -1,6 +1,6 @@
# Godot-specific ignores # Godot-specific ignores
.import/ .godot/
export.cfg export.cfg
export_presets.cfg export_presets.cfg

View file

@ -1,6 +1,6 @@
[gd_resource type="Environment" load_steps=2 format=2] [gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1] [sub_resource type="Sky" id=1]
[resource] [resource]
background_mode = 2 background_mode = 2

BIN
icon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

1
icon.svg Normal file
View file

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><g transform="translate(32 32)"><path d="m-16-32c-8.86 0-16 7.13-16 15.99v95.98c0 8.86 7.13 15.99 16 15.99h96c8.86 0 16-7.13 16-15.99v-95.98c0-8.85-7.14-15.99-16-15.99z" fill="#363d52"/><path d="m-16-32c-8.86 0-16 7.13-16 15.99v95.98c0 8.86 7.13 15.99 16 15.99h96c8.86 0 16-7.13 16-15.99v-95.98c0-8.85-7.14-15.99-16-15.99zm0 4h96c6.64 0 12 5.35 12 11.99v95.98c0 6.64-5.35 11.99-12 11.99h-96c-6.64 0-12-5.35-12-11.99v-95.98c0-6.64 5.36-11.99 12-11.99z" fill-opacity=".4"/></g><g stroke-width="9.92746" transform="matrix(.10073078 0 0 .10073078 12.425923 2.256365)"><path d="m0 0s-.325 1.994-.515 1.976l-36.182-3.491c-2.879-.278-5.115-2.574-5.317-5.459l-.994-14.247-27.992-1.997-1.904 12.912c-.424 2.872-2.932 5.037-5.835 5.037h-38.188c-2.902 0-5.41-2.165-5.834-5.037l-1.905-12.912-27.992 1.997-.994 14.247c-.202 2.886-2.438 5.182-5.317 5.46l-36.2 3.49c-.187.018-.324-1.978-.511-1.978l-.049-7.83 30.658-4.944 1.004-14.374c.203-2.91 2.551-5.263 5.463-5.472l38.551-2.75c.146-.01.29-.016.434-.016 2.897 0 5.401 2.166 5.825 5.038l1.959 13.286h28.005l1.959-13.286c.423-2.871 2.93-5.037 5.831-5.037.142 0 .284.005.423.015l38.556 2.75c2.911.209 5.26 2.562 5.463 5.472l1.003 14.374 30.645 4.966z" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 919.24059 771.67186)"/><path d="m0 0v-47.514-6.035-5.492c.108-.001.216-.005.323-.015l36.196-3.49c1.896-.183 3.382-1.709 3.514-3.609l1.116-15.978 31.574-2.253 2.175 14.747c.282 1.912 1.922 3.329 3.856 3.329h38.188c1.933 0 3.573-1.417 3.855-3.329l2.175-14.747 31.575 2.253 1.115 15.978c.133 1.9 1.618 3.425 3.514 3.609l36.182 3.49c.107.01.214.014.322.015v4.711l.015.005v54.325c5.09692 6.4164715 9.92323 13.494208 13.621 19.449-5.651 9.62-12.575 18.217-19.976 26.182-6.864-3.455-13.531-7.369-19.828-11.534-3.151 3.132-6.7 5.694-10.186 8.372-3.425 2.751-7.285 4.768-10.946 7.118 1.09 8.117 1.629 16.108 1.846 24.448-9.446 4.754-19.519 7.906-29.708 10.17-4.068-6.837-7.788-14.241-11.028-21.479-3.842.642-7.702.88-11.567.926v.006c-.027 0-.052-.006-.075-.006-.024 0-.049.006-.073.006v-.006c-3.872-.046-7.729-.284-11.572-.926-3.238 7.238-6.956 14.642-11.03 21.479-10.184-2.264-20.258-5.416-29.703-10.17.216-8.34.755-16.331 1.848-24.448-3.668-2.35-7.523-4.367-10.949-7.118-3.481-2.678-7.036-5.24-10.188-8.372-6.297 4.165-12.962 8.079-19.828 11.534-7.401-7.965-14.321-16.562-19.974-26.182 4.4426579-6.973692 9.2079702-13.9828876 13.621-19.449z" fill="#478cbf" transform="matrix(4.162611 0 0 -4.162611 104.69892 525.90697)"/><path d="m0 0-1.121-16.063c-.135-1.936-1.675-3.477-3.611-3.616l-38.555-2.751c-.094-.007-.188-.01-.281-.01-1.916 0-3.569 1.406-3.852 3.33l-2.211 14.994h-31.459l-2.211-14.994c-.297-2.018-2.101-3.469-4.133-3.32l-38.555 2.751c-1.936.139-3.476 1.68-3.611 3.616l-1.121 16.063-32.547 3.138c.015-3.498.06-7.33.06-8.093 0-34.374 43.605-50.896 97.781-51.086h.066.067c54.176.19 97.766 16.712 97.766 51.086 0 .777.047 4.593.063 8.093z" fill="#478cbf" transform="matrix(4.162611 0 0 -4.162611 784.07144 817.24284)"/><path d="m0 0c0-12.052-9.765-21.815-21.813-21.815-12.042 0-21.81 9.763-21.81 21.815 0 12.044 9.768 21.802 21.81 21.802 12.048 0 21.813-9.758 21.813-21.802" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 389.21484 625.67104)"/><path d="m0 0c0-7.994-6.479-14.473-14.479-14.473-7.996 0-14.479 6.479-14.479 14.473s6.483 14.479 14.479 14.479c8 0 14.479-6.485 14.479-14.479" fill="#414042" transform="matrix(4.162611 0 0 -4.162611 367.36686 631.05679)"/><path d="m0 0c-3.878 0-7.021 2.858-7.021 6.381v20.081c0 3.52 3.143 6.381 7.021 6.381s7.028-2.861 7.028-6.381v-20.081c0-3.523-3.15-6.381-7.028-6.381" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 511.99336 724.73954)"/><path d="m0 0c0-12.052 9.765-21.815 21.815-21.815 12.041 0 21.808 9.763 21.808 21.815 0 12.044-9.767 21.802-21.808 21.802-12.05 0-21.815-9.758-21.815-21.802" fill="#fff" transform="matrix(4.162611 0 0 -4.162611 634.78706 625.67104)"/><path d="m0 0c0-7.994 6.477-14.473 14.471-14.473 8.002 0 14.479 6.479 14.479 14.473s-6.477 14.479-14.479 14.479c-7.994 0-14.471-6.485-14.471-14.479" fill="#414042" transform="matrix(4.162611 0 0 -4.162611 656.64056 631.05679)"/></g></svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

37
icon.svg.import Normal file
View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://1i2be24l5nbt"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View file

@ -1,8 +1,9 @@
[remap] [remap]
importer="texture" importer="texture"
type="StreamTexture" type="CompressedTexture2D"
path="res://.import/joystick_base_outline.png-483e8f1ac02a5b9a594f81d7e341a76f.stex" uid="uid://c13dhmpklvcb4"
path="res://.godot/imported/joystick_base_outline.png-483e8f1ac02a5b9a594f81d7e341a76f.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
@ -10,26 +11,24 @@ metadata={
[deps] [deps]
source_file="res://joystick/textures/joystick_base_outline.png" source_file="res://joystick/textures/joystick_base_outline.png"
dest_files=[ "res://.import/joystick_base_outline.png-483e8f1ac02a5b9a594f81d7e341a76f.stex" ] dest_files=["res://.godot/imported/joystick_base_outline.png-483e8f1ac02a5b9a594f81d7e341a76f.ctex"]
[params] [params]
compress/mode=0 compress/mode=0
compress/lossy_quality=0.7 compress/lossy_quality=0.7
compress/hdr_mode=0 compress/hdr_compression=1
compress/bptc_ldr=0 compress/bptc_ldr=0
compress/normal_map=0 compress/normal_map=0
flags/repeat=0 compress/channel_pack=0
flags/filter=true mipmaps/generate=false
flags/mipmaps=false mipmaps/limit=-1
flags/anisotropic=false roughness/mode=0
flags/srgb=2 roughness/src_normal=""
process/fix_alpha_border=true process/fix_alpha_border=true
process/premult_alpha=false process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false process/normal_map_invert_y=false
stream=false process/hdr_as_srgb=false
size_limit=0 process/hdr_clamp_exposure=false
detect_3d=true process/size_limit=0
svg/scale=1.0 detect_3d/compress_to=1

View file

@ -1,8 +1,9 @@
[remap] [remap]
importer="texture" importer="texture"
type="StreamTexture" type="CompressedTexture2D"
path="res://.import/joystick_tip.png-3a18c9ea76fb1ca4d2905a9a7401093a.stex" uid="uid://clcwu3hgw3euc"
path="res://.godot/imported/joystick_tip.png-3a18c9ea76fb1ca4d2905a9a7401093a.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
@ -10,26 +11,24 @@ metadata={
[deps] [deps]
source_file="res://joystick/textures/joystick_tip.png" source_file="res://joystick/textures/joystick_tip.png"
dest_files=[ "res://.import/joystick_tip.png-3a18c9ea76fb1ca4d2905a9a7401093a.stex" ] dest_files=["res://.godot/imported/joystick_tip.png-3a18c9ea76fb1ca4d2905a9a7401093a.ctex"]
[params] [params]
compress/mode=0 compress/mode=0
compress/lossy_quality=0.7 compress/lossy_quality=0.7
compress/hdr_mode=0 compress/hdr_compression=1
compress/bptc_ldr=0 compress/bptc_ldr=0
compress/normal_map=0 compress/normal_map=0
flags/repeat=0 compress/channel_pack=0
flags/filter=true mipmaps/generate=false
flags/mipmaps=false mipmaps/limit=-1
flags/anisotropic=false roughness/mode=0
flags/srgb=2 roughness/src_normal=""
process/fix_alpha_border=true process/fix_alpha_border=true
process/premult_alpha=false process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false process/normal_map_invert_y=false
stream=false process/hdr_as_srgb=false
size_limit=0 process/hdr_clamp_exposure=false
detect_3d=true process/size_limit=0
svg/scale=1.0 detect_3d/compress_to=1

View file

@ -1,8 +1,9 @@
[remap] [remap]
importer="texture" importer="texture"
type="StreamTexture" type="CompressedTexture2D"
path="res://.import/joystick_tip_arrows.png-c9482441a78cf839baf32238aae88b91.stex" uid="uid://bprmb464pp766"
path="res://.godot/imported/joystick_tip_arrows.png-c9482441a78cf839baf32238aae88b91.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
@ -10,26 +11,24 @@ metadata={
[deps] [deps]
source_file="res://joystick/textures/joystick_tip_arrows.png" source_file="res://joystick/textures/joystick_tip_arrows.png"
dest_files=[ "res://.import/joystick_tip_arrows.png-c9482441a78cf839baf32238aae88b91.stex" ] dest_files=["res://.godot/imported/joystick_tip_arrows.png-c9482441a78cf839baf32238aae88b91.ctex"]
[params] [params]
compress/mode=0 compress/mode=0
compress/lossy_quality=0.7 compress/lossy_quality=0.7
compress/hdr_mode=0 compress/hdr_compression=1
compress/bptc_ldr=0 compress/bptc_ldr=0
compress/normal_map=0 compress/normal_map=0
flags/repeat=0 compress/channel_pack=0
flags/filter=true mipmaps/generate=false
flags/mipmaps=false mipmaps/limit=-1
flags/anisotropic=false roughness/mode=0
flags/srgb=2 roughness/src_normal=""
process/fix_alpha_border=true process/fix_alpha_border=true
process/premult_alpha=false process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false process/normal_map_invert_y=false
stream=false process/hdr_as_srgb=false
size_limit=0 process/hdr_clamp_exposure=false
detect_3d=true process/size_limit=0
svg/scale=1.0 detect_3d/compress_to=1

View file

@ -6,68 +6,81 @@ extends Control
#### EXPORTED VARIABLE #### #### EXPORTED VARIABLE ####
# The color of the button when the joystick is in use. ## The color modulation of the button when the joystick is in use. See [member CanvasItem.modulate].
export(Color) var pressed_color := Color.gray @export var pressed_color: Color = Color.GRAY
# If the input is inside this range, the output is zero. ## If the input is inside this range, the output is zero.
export(float, 0, 200, 1) var deadzone_size : float = 10 @export_range(0, 200, 1) var deadzone_size : float = 10
# The max distance the tip can reach. ## The max distance the tip can reach.
export(float, 0, 500, 1) var clampzone_size : float = 75 @export_range(0, 500, 1) var clampzone_size : float = 75
# FIXED: The joystick doesn't move. enum JoystickMode {
# DYNAMIC: Every time the joystick area is pressed, the joystick position is set on the touched position. FIXED, ## The joystick doesn't move. Default.
enum JoystickMode {FIXED, DYNAMIC} DYNAMIC ## Every time the joystick area is pressed, the joystick position is set on the touched position.
}
export(JoystickMode) var joystick_mode := JoystickMode.FIXED ## Whether the joystick should move on pressed.
@export var joystick_mode: JoystickMode = JoystickMode.FIXED
# VISIBILITY_ALWAYS = Always visible. enum VisibilityMode {
# VISIBILITY_TOUCHSCREEN_ONLY = Visible on touch screens only. ALWAYS, ## Always visible. Default.
enum VisibilityMode {ALWAYS , TOUCHSCREEN_ONLY } TOUCHSCREEN_ONLY ## Visible on touch screens only.
}
export(VisibilityMode) var visibility_mode := VisibilityMode.ALWAYS ## Whether or not the joystick is visible if there is no touchscreen
@export var visibility_mode: VisibilityMode = VisibilityMode.ALWAYS
# Use Input Actions ## If [code]true[/code], the value returned from [method Input.get_axis] using
export var use_input_actions := true ## [member action_left], [member action_right], [member action_up], and [member action_down]
## are overridden with [member output] for each axis such that
## [code]Input.get_axis(action_left, action_right)[/code] should always equal [member output.x] and
## [code]Input.get_axis(action_up, action_down)[/code] should always equal [member output.y][br]
## See [b]Project → Project Settings → Input Map[/b][br]
## If you want to change the hotkeys for the default actions make sure [b]Show Built-in Action[/b] is checked.
@export var use_input_actions := true
# Project -> Project Settings -> Input Map ## Input action for left direction
export var action_left := "ui_left" @export var action_left := "ui_left"
export var action_right := "ui_right" ## Input action for right direction
export var action_up := "ui_up" @export var action_right := "ui_right"
export var action_down := "ui_down" ## Input action for up direction
@export var action_up := "ui_up"
## Input action for down direction
@export var action_down := "ui_down"
#### PUBLIC VARIABLES #### #### PUBLIC VARIABLES ####
# If the joystick is receiving inputs. ## If [code]true[/code], the joystick's state is pressed. Means the joystick will receive inputs.
var _pressed := false setget , is_pressed var pressed := false : get = is_pressed
func is_pressed() -> bool: func is_pressed() -> bool:
return _pressed return pressed
# The joystick output. ## Current position of the joystick. The value's length ranges from [code]0[/code] to [code]1.0[/code].
var _output := Vector2.ZERO setget , get_output var output := Vector2.ZERO : get = get_output
func get_output() -> Vector2: func get_output() -> Vector2:
return _output return output
#### PRIVATE VARIABLES #### #### PRIVATE VARIABLES ####
var _touch_index : int = -1 var _touch_index : int = -1
onready var _base := $Base @onready var _base := $Base
onready var _tip := $Base/Tip @onready var _tip := $Base/Tip
onready var _base_radius = _base.rect_size * _base.get_global_transform_with_canvas().get_scale() / 2 @onready var _base_radius = _base.size * _base.get_global_transform_with_canvas().get_scale() / 2
onready var _base_default_position : Vector2 = _base.rect_position @onready var _base_default_position : Vector2 = _base.position
onready var _tip_default_position : Vector2 = _tip.rect_position @onready var _tip_default_position : Vector2 = _tip.position
onready var _default_color : Color = _tip.modulate @onready var _default_color : Color = _tip.modulate
#### FUNCTIONS #### #### FUNCTIONS ####
func _ready() -> void: func _ready() -> void:
if not OS.has_touchscreen_ui_hint() and visibility_mode == VisibilityMode.TOUCHSCREEN_ONLY: if not DisplayServer.is_touchscreen_available() and visibility_mode == VisibilityMode.TOUCHSCREEN_ONLY:
hide() hide()
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
@ -80,28 +93,28 @@ func _input(event: InputEvent) -> void:
_touch_index = event.index _touch_index = event.index
_tip.modulate = pressed_color _tip.modulate = pressed_color
_update_joystick(event.position) _update_joystick(event.position)
get_tree().set_input_as_handled() get_viewport().set_input_as_handled()
elif event.index == _touch_index: elif event.index == _touch_index:
_reset() _reset()
get_tree().set_input_as_handled() get_viewport().set_input_as_handled()
elif event is InputEventScreenDrag: elif event is InputEventScreenDrag:
if event.index == _touch_index: if event.index == _touch_index:
_update_joystick(event.position) _update_joystick(event.position)
get_tree().set_input_as_handled() get_viewport().set_input_as_handled()
func _move_base(new_position: Vector2) -> void: func _move_base(new_position: Vector2) -> void:
_base.rect_global_position = new_position - _base.rect_pivot_offset * get_global_transform_with_canvas().get_scale() _base.global_position = new_position - _base.pivot_offset * get_global_transform_with_canvas().get_scale()
func _move_tip(new_position: Vector2) -> void: func _move_tip(new_position: Vector2) -> void:
_tip.rect_global_position = new_position - _tip.rect_pivot_offset * _base.get_global_transform_with_canvas().get_scale() _tip.global_position = new_position - _tip.pivot_offset * _base.get_global_transform_with_canvas().get_scale()
func _is_point_inside_joystick_area(point: Vector2) -> bool: func _is_point_inside_joystick_area(point: Vector2) -> bool:
var x: bool = point.x >= rect_global_position.x and point.x <= rect_global_position.x + (rect_size.x * get_global_transform_with_canvas().get_scale().x) var x: bool = point.x >= global_position.x and point.x <= global_position.x + (size.x * get_global_transform_with_canvas().get_scale().x)
var y: bool = point.y >= rect_global_position.y and point.y <= rect_global_position.y + (rect_size.y * get_global_transform_with_canvas().get_scale().y) var y: bool = point.y >= global_position.y and point.y <= global_position.y + (size.y * get_global_transform_with_canvas().get_scale().y)
return x and y return x and y
func _is_point_inside_base(point: Vector2) -> bool: func _is_point_inside_base(point: Vector2) -> bool:
var center : Vector2 = _base.rect_global_position + _base_radius var center : Vector2 = _base.global_position + _base_radius
var vector : Vector2 = point - center var vector : Vector2 = point - center
if vector.length_squared() <= _base_radius.x * _base_radius.x: if vector.length_squared() <= _base_radius.x * _base_radius.x:
return true return true
@ -109,53 +122,53 @@ func _is_point_inside_base(point: Vector2) -> bool:
return false return false
func _update_joystick(touch_position: Vector2) -> void: func _update_joystick(touch_position: Vector2) -> void:
var center : Vector2 = _base.rect_global_position + _base_radius var center : Vector2 = _base.global_position + _base_radius
var vector : Vector2 = touch_position - center var vector : Vector2 = touch_position - center
vector = vector.limit_length(clampzone_size) vector = vector.limit_length(clampzone_size)
_move_tip(center + vector) _move_tip(center + vector)
if vector.length_squared() > deadzone_size * deadzone_size: if vector.length_squared() > deadzone_size * deadzone_size:
_pressed = true pressed = true
_output = (vector - (vector.normalized() * deadzone_size)) / (clampzone_size - deadzone_size) output = (vector - (vector.normalized() * deadzone_size)) / (clampzone_size - deadzone_size)
else: else:
_pressed = false pressed = false
_output = Vector2.ZERO output = Vector2.ZERO
if use_input_actions: if use_input_actions:
_update_input_actions() _update_input_actions()
func _update_input_actions(): func _update_input_actions():
if _output.x < 0: if output.x < 0:
Input.action_press(action_left, -_output.x) Input.action_press(action_left, -output.x)
elif Input.is_action_pressed(action_left): elif Input.is_action_pressed(action_left):
Input.action_release(action_left) Input.action_release(action_left)
if _output.x > 0: if output.x > 0:
Input.action_press(action_right, _output.x) Input.action_press(action_right, output.x)
elif Input.is_action_pressed(action_right): elif Input.is_action_pressed(action_right):
Input.action_release(action_right) Input.action_release(action_right)
if _output.y < 0: if output.y < 0:
Input.action_press(action_up, -_output.y) Input.action_press(action_up, -output.y)
elif Input.is_action_pressed(action_up): elif Input.is_action_pressed(action_up):
Input.action_release(action_up) Input.action_release(action_up)
if _output.y > 0: if output.y > 0:
Input.action_press(action_down, _output.y) Input.action_press(action_down, output.y)
elif Input.is_action_pressed(action_down): elif Input.is_action_pressed(action_down):
Input.action_release(action_down) Input.action_release(action_down)
func _reset(): func _reset():
_pressed = false pressed = false
_output = Vector2.ZERO output = Vector2.ZERO
_touch_index = -1 _touch_index = -1
_tip.modulate = _default_color _tip.modulate = _default_color
_base.rect_position = _base_default_position _base.position = _base_default_position
_tip.rect_position = _tip_default_position _tip.position = _tip_default_position
if use_input_actions: if use_input_actions:
if Input.is_action_pressed(action_left) or Input.is_action_just_pressed(action_left): if Input.is_action_pressed(action_left):
Input.action_release(action_left) Input.action_release(action_left)
if Input.is_action_pressed(action_right) or Input.is_action_just_pressed(action_right): if Input.is_action_pressed(action_right):
Input.action_release(action_right) Input.action_release(action_right)
if Input.is_action_pressed(action_down) or Input.is_action_just_pressed(action_down): if Input.is_action_pressed(action_down):
Input.action_release(action_down) Input.action_release(action_down)
if Input.is_action_pressed(action_up) or Input.is_action_just_pressed(action_up): if Input.is_action_pressed(action_up):
Input.action_release(action_up) Input.action_release(action_up)

View file

@ -1,58 +1,54 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=4 format=3 uid="uid://buyvavyuwmccw"]
[ext_resource path="res://joystick/textures/joystick_base_outline.png" type="Texture" id=1] [ext_resource type="Texture2D" uid="uid://c13dhmpklvcb4" path="res://joystick/textures/joystick_base_outline.png" id="1"]
[ext_resource path="res://joystick/textures/joystick_tip_arrows.png" type="Texture" id=2] [ext_resource type="Texture2D" uid="uid://bprmb464pp766" path="res://joystick/textures/joystick_tip_arrows.png" id="2"]
[ext_resource path="res://joystick/virtual_joystick.gd" type="Script" id=3] [ext_resource type="Script" path="res://joystick/virtual_joystick.gd" id="3"]
[node name="Virtual joystick" type="Control"] [node name="Virtual joystick" type="Control"]
modulate = Color( 1, 1, 1, 0.509804 ) modulate = Color(1, 1, 1, 0.509804)
layout_mode = 3
anchors_preset = 2
anchor_top = 1.0 anchor_top = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_left = 50.0 offset_left = 50.0
margin_top = -250.0 offset_top = -250.0
margin_right = 250.0 offset_right = 250.0
margin_bottom = -50.0 offset_bottom = -50.0
script = ExtResource( 3 ) grow_vertical = 0
__meta__ = { script = ExtResource("3")
"_edit_use_anchors_": false
}
[node name="Base" type="TextureRect" parent="."] [node name="Base" type="TextureRect" parent="."]
layout_mode = 0
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
margin_left = -100.0 offset_left = -100.0
margin_top = -100.0 offset_top = -100.0
margin_right = 100.0 offset_right = 100.0
margin_bottom = 100.0 offset_bottom = 100.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
rect_pivot_offset = Vector2( 100, 100 ) pivot_offset = Vector2(100, 100)
size_flags_horizontal = 4 size_flags_horizontal = 4
size_flags_vertical = 4 size_flags_vertical = 4
texture = ExtResource( 1 ) texture = ExtResource("1")
stretch_mode = 6 stretch_mode = 6
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Tip" type="TextureRect" parent="Base"] [node name="Tip" type="TextureRect" parent="Base"]
layout_mode = 0
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
margin_left = -50.0 offset_left = -50.0
margin_top = -50.0 offset_top = -50.0
margin_right = 50.0 offset_right = 50.0
margin_bottom = 50.0 offset_bottom = 50.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
rect_pivot_offset = Vector2( 50, 50 ) pivot_offset = Vector2(50, 50)
size_flags_horizontal = 4 size_flags_horizontal = 4
size_flags_vertical = 4 size_flags_vertical = 4
texture = ExtResource( 2 ) texture = ExtResource("2")
stretch_mode = 6 stretch_mode = 6
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -0,0 +1,3 @@
[remap]
importer="keep"

3
previews/icon.png.import Normal file
View file

@ -0,0 +1,3 @@
[remap]
importer="keep"

View file

@ -0,0 +1,3 @@
[remap]
importer="keep"

View file

@ -0,0 +1,3 @@
[remap]
importer="keep"

View file

@ -0,0 +1,3 @@
[remap]
importer="keep"

View file

@ -6,26 +6,19 @@
; [section] ; section goes between [] ; [section] ; section goes between []
; param=value ; assign values to parameters ; param=value ; assign values to parameters
config_version=4 config_version=5
_global_script_classes=[ {
"base": "Control",
"class": "VirtualJoystick",
"language": "GDScript",
"path": "res://joystick/virtual_joystick.gd"
} ]
_global_script_class_icons={
"VirtualJoystick": ""
}
[application] [application]
config/name="Virtual Joystick" config/name="Virtual Joystick"
run/main_scene="res://test/test.tscn" run/main_scene="res://test/test.tscn"
config/icon="res://icon.png" config/features=PackedStringArray("4.0")
config/icon="res://icon.svg"
[display] [display]
window/size/viewport_width=1024
window/size/viewport_height=600
window/handheld/orientation="sensor_landscape" window/handheld/orientation="sensor_landscape"
window/stretch/mode="2d" window/stretch/mode="2d"
window/stretch/aspect="expand" window/stretch/aspect="expand"

View file

@ -1,12 +1,10 @@
extends Sprite extends Sprite2D
export (NodePath) var joystickLeftPath @export var joystickLeft : VirtualJoystick = null
onready var joystickLeft : VirtualJoystick = get_node(joystickLeftPath)
export var speed : float = 100 @export var speed : float = 100
export (NodePath) var joystickRightPath @export var joystickRight : VirtualJoystick = null
onready var joystickRight : VirtualJoystick = get_node(joystickRightPath)
func _process(delta: float) -> void: func _process(delta: float) -> void:
# # Movement using the joystick output: # # Movement using the joystick output:

View file

@ -1,27 +1,30 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=4 format=3 uid="uid://dobxmb2308lcr"]
[ext_resource path="res://icon.png" type="Texture" id=1] [ext_resource type="PackedScene" uid="uid://buyvavyuwmccw" path="res://joystick/virtual_joystick.tscn" id="2"]
[ext_resource path="res://joystick/virtual_joystick.tscn" type="PackedScene" id=2] [ext_resource type="Texture2D" uid="uid://1i2be24l5nbt" path="res://icon.svg" id="2_eu1q5"]
[ext_resource path="res://test/player.gd" type="Script" id=3] [ext_resource type="Script" path="res://test/player.gd" id="3"]
[node name="Node" type="Node"] [node name="Node" type="Node"]
[node name="UI" type="CanvasLayer" parent="."] [node name="UI" type="CanvasLayer" parent="."]
[node name="Virtual joystick" parent="UI" instance=ExtResource( 2 )] [node name="Virtual joystick" parent="UI" instance=ExtResource("2")]
[node name="Virtual joystick2" parent="UI" instance=ExtResource( 2 )] [node name="Virtual joystick2" parent="UI" instance=ExtResource("2")]
anchors_preset = 3
anchor_left = 1.0 anchor_left = 1.0
anchor_right = 1.0 anchor_right = 1.0
margin_left = -250.0 offset_left = -250.0
margin_right = -50.0 offset_top = -200.0
offset_right = -50.0
offset_bottom = 0.0
grow_horizontal = 0
joystick_mode = 1 joystick_mode = 1
use_input_actions = false use_input_actions = false
[node name="Icon" type="Sprite" parent="."] [node name="Icon" type="Sprite2D" parent="." node_paths=PackedStringArray("joystickLeft", "joystickRight")]
position = Vector2( 512, 300 ) position = Vector2(512, 300)
scale = Vector2( 2, 2 ) texture = ExtResource("2_eu1q5")
texture = ExtResource( 1 ) script = ExtResource("3")
script = ExtResource( 3 ) joystickLeft = NodePath("../UI/Virtual joystick")
joystickLeftPath = NodePath("../UI/Virtual joystick") joystickRight = NodePath("../UI/Virtual joystick2")
joystickRightPath = NodePath("../UI/Virtual joystick2")