Added Cursor Node
Digital cursor, follows & hides mouse Hide Mouse can be disabled by ShowMouse = true
This commit is contained in:
11
game/Main.tscn
Normal file
11
game/Main.tscn
Normal file
@@ -0,0 +1,11 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cdeww5uc20038"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ccydu80643k4s" path="res://Scripts/CursorScript.gd" id="1_uu6xs"]
|
||||
[ext_resource type="Texture2D" uid="uid://d0hckoql2xnbq" path="res://Textures/svg/Cursor.svg" id="2_r0du0"]
|
||||
|
||||
[node name="Cursor" type="Node2D"]
|
||||
script = ExtResource("1_uu6xs")
|
||||
ShowMouse = true
|
||||
|
||||
[node name="CursorTexture" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_r0du0")
|
||||
29
game/Scripts/CursorScript.gd
Normal file
29
game/Scripts/CursorScript.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
extends Node2D
|
||||
@onready var Cursor = $Cursor
|
||||
@export var ShowMouse = false
|
||||
var old_mouse_pos = Vector2.ZERO
|
||||
var mouse_velocity = Vector2.ZERO
|
||||
#var speed = 5000.0
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
if not ShowMouse : Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
||||
old_mouse_pos = get_viewport().get_mouse_position()
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
var current_mouse_pos = get_viewport().get_mouse_position()
|
||||
|
||||
mouse_velocity = current_mouse_pos - old_mouse_pos
|
||||
|
||||
if mouse_velocity.length_squared()>0.1:
|
||||
rotation = mouse_velocity.angle()
|
||||
|
||||
var direction_to_mouse = (current_mouse_pos - global_position).normalized()
|
||||
global_position = current_mouse_pos
|
||||
|
||||
old_mouse_pos = current_mouse_pos
|
||||
pass
|
||||
1
game/Scripts/CursorScript.gd.uid
Normal file
1
game/Scripts/CursorScript.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ccydu80643k4s
|
||||
1
game/Textures/svg/Cursor.svg
Normal file
1
game/Textures/svg/Cursor.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="54.7575" height="54.7575" viewBox="0,0,54.7575,54.7575"><g transform="translate(-372.62125,-372.62125)"><g stroke-miterlimit="10"><path d="M375.12125,400c0,-13.74015 11.1386,-24.87875 24.87875,-24.87875c13.74015,0 24.87875,11.1386 24.87875,24.87875c0,13.74015 -11.1386,24.87875 -24.87875,24.87875c-13.74015,0 -24.87875,-11.1386 -24.87875,-24.87875z" fill="#ff00e4" stroke="#000000" stroke-width="5"/><path d="M421.23866,400l-11.85733,13.72621v-27.45241z" fill="#ffffff" stroke="#001919" stroke-width="0.5"/></g></g></svg><!--rotationCenter:27.378748589491465:27.378748589491465-->
|
||||
|
After Width: | Height: | Size: 684 B |
37
game/Textures/svg/Cursor.svg.import
Normal file
37
game/Textures/svg/Cursor.svg.import
Normal file
@@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://d0hckoql2xnbq"
|
||||
path="res://.godot/imported/Cursor.svg-2229e5b0ea8173aa59b52a7080f1b61c.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Textures/svg/Cursor.svg"
|
||||
dest_files=["res://.godot/imported/Cursor.svg-2229e5b0ea8173aa59b52a7080f1b61c.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
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
|
||||
Reference in New Issue
Block a user