Initial commit
This commit is contained in:
24
test/player.gd
Normal file
24
test/player.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
extends Sprite2D
|
||||
|
||||
@export var speed : float = 100
|
||||
|
||||
@export var joystick_left : VirtualJoystick
|
||||
|
||||
@export var joystick_right : VirtualJoystick
|
||||
|
||||
var move_vector := Vector2.ZERO
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# # Movement using the joystick output:
|
||||
# if joystick_left and joystick_left.is_pressed:
|
||||
# position += joystick_left.output * speed * delta
|
||||
|
||||
# Movement using Input functions:
|
||||
move_vector = Vector2.ZERO
|
||||
move_vector.x = Input.get_axis("ui_left", "ui_right")
|
||||
move_vector.y = Input.get_axis("ui_up", "ui_down")
|
||||
position += move_vector * speed * delta
|
||||
|
||||
# Rotation:
|
||||
if joystick_right and joystick_right.is_pressed:
|
||||
rotation = joystick_right.output.angle()
|
||||
30
test/test.tscn
Normal file
30
test/test.tscn
Normal file
@@ -0,0 +1,30 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bq2sqb1u1l5ve"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dmr0fcamx7t56" path="res://joystick/virtual_joystick.tscn" id="1_4k4lh"]
|
||||
[ext_resource type="Texture2D" uid="uid://b4jy3cynf4voa" path="res://icon.svg" id="2_44wa8"]
|
||||
[ext_resource type="Script" path="res://test/player.gd" id="3_dsmxw"]
|
||||
|
||||
[node name="Test" type="Node2D"]
|
||||
|
||||
[node name="UI" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Virtual joystick left" parent="UI" instance=ExtResource("1_4k4lh")]
|
||||
|
||||
[node name="Virtual joystick right" parent="UI" instance=ExtResource("1_4k4lh")]
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -300.0
|
||||
offset_top = -300.0
|
||||
offset_right = 0.0
|
||||
offset_bottom = 0.0
|
||||
grow_horizontal = 0
|
||||
joystick_mode = 1
|
||||
use_input_actions = false
|
||||
|
||||
[node name="Player" type="Sprite2D" parent="." node_paths=PackedStringArray("joystick_left", "joystick_right")]
|
||||
position = Vector2(600, 300)
|
||||
texture = ExtResource("2_44wa8")
|
||||
script = ExtResource("3_dsmxw")
|
||||
joystick_left = NodePath("../UI/Virtual joystick left")
|
||||
joystick_right = NodePath("../UI/Virtual joystick right")
|
||||
Reference in New Issue
Block a user