button?
This commit is contained in:
BIN
entities/button/button.aseprite
Normal file
BIN
entities/button/button.aseprite
Normal file
Binary file not shown.
28
entities/button/button.aseprite.import
Normal file
28
entities/button/button.aseprite.import
Normal file
@@ -0,0 +1,28 @@
|
||||
[remap]
|
||||
|
||||
importer="Aseprite SpriteFrames"
|
||||
type="SpriteFrames"
|
||||
uid="uid://b31mdngbhms7k"
|
||||
path="res://.godot/imported/button.aseprite-330c6544a3de5fb54bfcd807901558f0.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/button/button.aseprite"
|
||||
dest_files=["res://.godot/imported/button.aseprite-330c6544a3de5fb54bfcd807901558f0.res"]
|
||||
|
||||
[params]
|
||||
|
||||
animation/default/name="default"
|
||||
animation/default/direction=0
|
||||
animation/default/repeat_count=0
|
||||
animation/autoplay_name=""
|
||||
atlas_textures/region_filter_clip_enabled=false
|
||||
middle_import_script=""
|
||||
post_import_script=""
|
||||
sprite_sheet/edges_artifacts_avoidance_method=0
|
||||
sprite_sheet/sprites_surrounding_color=Color(1, 1, 1, 0)
|
||||
sprite_sheet/layout=0
|
||||
sprite_sheet/max_cells_in_strip=0
|
||||
sprite_sheet/trim_sprites_to_overall_min_size=true
|
||||
sprite_sheet/collapse_transparent_sprites=true
|
||||
sprite_sheet/merge_duplicated_sprites=true
|
||||
BIN
entities/button/button.aseprite.png
Normal file
BIN
entities/button/button.aseprite.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 583 B |
34
entities/button/button.aseprite.png.import
Normal file
34
entities/button/button.aseprite.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://m8ophji4p35i"
|
||||
path="res://.godot/imported/button.aseprite.png-65b0b5c35c3c69ebe0561afd09528d1a.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://entities/button/button.aseprite.png"
|
||||
dest_files=["res://.godot/imported/button.aseprite.png-65b0b5c35c3c69ebe0561afd09528d1a.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
|
||||
17
entities/button/button.tscn
Normal file
17
entities/button/button.tscn
Normal file
@@ -0,0 +1,17 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://q3f3j7p3t43w"]
|
||||
|
||||
[ext_resource type="SpriteFrames" uid="uid://b31mdngbhms7k" path="res://entities/button/button.aseprite" id="1_4tlb3"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_4tlb3"]
|
||||
radius = 13.0
|
||||
|
||||
[node name="Button" type="Node2D"]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = ExtResource("1_4tlb3")
|
||||
animation = &"Press"
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource("CircleShape2D_4tlb3")
|
||||
Binary file not shown.
@@ -1,17 +1,54 @@
|
||||
# This script controls a top-down player character using input and rotates towards the mouse or right stick.
|
||||
extends CharacterBody2D
|
||||
|
||||
# Player movement speed (pixels per second)
|
||||
@export var speed = 200
|
||||
|
||||
const SPEED = 300.0
|
||||
@export var friction = 16
|
||||
|
||||
# Rotation speed (radians per second) - adjust for desired rotation speed
|
||||
@export var rotation_speed = PI * 4 # Rotate 2 full circles per second
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Use mouse for rotation? If false, uses gamepad right stick.
|
||||
@export var rotate_with_mouse = true
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction := Input.get_vector("ui_left", "ui_right","ui_up", "ui_down")
|
||||
if direction:
|
||||
velocity = direction * SPEED
|
||||
# Called every physics frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta):
|
||||
# --- Movement Logic ---
|
||||
var input_vector = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
|
||||
# Set the velocity based on input
|
||||
if input_vector != Vector2.ZERO:
|
||||
velocity = input_vector * speed
|
||||
else:
|
||||
velocity = lerp(velocity, Vector2.ZERO, 0.75)
|
||||
# If no input, stop the player (optional, you might want friction instead)
|
||||
velocity = lerp(velocity, Vector2.ZERO, friction * delta)
|
||||
|
||||
# Move the player and handle collisions using CharacterBody2D's move_and_slide
|
||||
move_and_slide()
|
||||
|
||||
# --- Rotation Logic ---
|
||||
var target_rotation_direction = Vector2.ZERO
|
||||
|
||||
if rotate_with_mouse:
|
||||
# Get the mouse position in world coordinates
|
||||
var mouse_position = get_global_mouse_position()
|
||||
# Calculate the direction vector from the player to the mouse
|
||||
target_rotation_direction = global_position.direction_to(mouse_position)
|
||||
else:
|
||||
# Get right analog stick input
|
||||
target_rotation_direction = Input.get_vector("rotate_left", "rotate_right", "rotate_up", "rotate_down")
|
||||
|
||||
# If there is a valid rotation direction (either from mouse or stick input)
|
||||
if target_rotation_direction != Vector2.ZERO:
|
||||
# Calculate the target rotation angle in radians
|
||||
var target_angle = target_rotation_direction.angle()
|
||||
|
||||
# Smoothly rotate the player towards the target angle
|
||||
# Using lerp_angle for smooth interpolation of angles
|
||||
rotation = lerp_angle(rotation, target_angle, rotation_speed * delta)
|
||||
|
||||
# Note: Make sure you have input actions configured in Project Settings -> Input Map:
|
||||
# - "move_up", "move_down", "move_left", "move_right" for movement.
|
||||
# - If not using mouse rotation, add "rotate_up", "rotate_down", "rotate_left", "rotate_right"
|
||||
# and map them to the right analog stick axes (e.g., Joy Axis 4- for left, Joy Axis 4+ for right, etc.)
|
||||
|
||||
@@ -15,3 +15,5 @@ shape = SubResource("CircleShape2D_sfv1e")
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
self_modulate = Color(0.223529, 1, 1, 1)
|
||||
texture = ExtResource("2_abrql")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
|
||||
Reference in New Issue
Block a user