├── icon.png ├── AnimatedBtnIcon.png ├── addons └── animatedbutton │ ├── plugin.cfg │ ├── Button.svg │ ├── plugin.gd │ ├── Button.svg.import │ └── AnimatedButton.gd ├── .gitignore ├── project.godot ├── icon.png.import ├── AnimatedBtnIcon.png.import ├── LICENSE ├── README.md └── demo └── demo.tscn /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdilDevStuff/AnimatedButton/HEAD/icon.png -------------------------------------------------------------------------------- /AnimatedBtnIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdilDevStuff/AnimatedButton/HEAD/AnimatedBtnIcon.png -------------------------------------------------------------------------------- /addons/animatedbutton/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name="AnimatedButton" 4 | description="" 5 | author="AdilDevStuff" 6 | version="0.2" 7 | script="plugin.gd" 8 | -------------------------------------------------------------------------------- /addons/animatedbutton/Button.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Godot 4+ specific ignores 2 | .godot/ 3 | 4 | # Godot-specific ignores 5 | .import/ 6 | export.cfg 7 | export_presets.cfg 8 | 9 | # Imported translations (automatically generated from CSV files) 10 | *.translation 11 | 12 | # Mono-specific ignores 13 | .mono/ 14 | data_*/ 15 | mono_crash.*.json 16 | -------------------------------------------------------------------------------- /addons/animatedbutton/plugin.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends EditorPlugin 3 | 4 | var type_name: String = "AnimatedButton" 5 | var animated_btn_script = preload("res://addons/animatedbutton/AnimatedButton.gd") 6 | var btn_icon = preload("res://addons/animatedbutton/Button.svg") 7 | 8 | func _enter_tree() -> void: 9 | add_custom_type(type_name, "Button", animated_btn_script, btn_icon) 10 | 11 | func _exit_tree() -> void: 12 | remove_custom_type(type_name) 13 | -------------------------------------------------------------------------------- /project.godot: -------------------------------------------------------------------------------- 1 | ; Engine configuration file. 2 | ; It's best edited using the editor UI and not directly, 3 | ; since the parameters that go here are not all obvious. 4 | ; 5 | ; Format: 6 | ; [section] ; section goes between [] 7 | ; param=value ; assign values to parameters 8 | 9 | config_version=5 10 | 11 | [application] 12 | 13 | config/name="AnimatedButton" 14 | run/main_scene="res://demo/demo.tscn" 15 | config/features=PackedStringArray("4.3") 16 | config/icon="res://icon.png" 17 | 18 | [editor_plugins] 19 | 20 | enabled=PackedStringArray("res://addons/animatedbutton/plugin.cfg") 21 | -------------------------------------------------------------------------------- /icon.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://dseorfigrt71n" 6 | path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex" 7 | metadata={ 8 | "vram_texture": false 9 | } 10 | 11 | [deps] 12 | 13 | source_file="res://icon.png" 14 | dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"] 15 | 16 | [params] 17 | 18 | compress/mode=0 19 | compress/high_quality=false 20 | compress/lossy_quality=0.7 21 | compress/hdr_compression=1 22 | compress/normal_map=0 23 | compress/channel_pack=0 24 | mipmaps/generate=false 25 | mipmaps/limit=-1 26 | roughness/mode=0 27 | roughness/src_normal="" 28 | process/fix_alpha_border=true 29 | process/premult_alpha=false 30 | process/normal_map_invert_y=false 31 | process/hdr_as_srgb=false 32 | process/hdr_clamp_exposure=false 33 | process/size_limit=0 34 | detect_3d/compress_to=1 35 | -------------------------------------------------------------------------------- /AnimatedBtnIcon.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://qh6cq7xx23um" 6 | path="res://.godot/imported/AnimatedBtnIcon.png-7832b89487ab8cf89f4bd4172b8bef33.ctex" 7 | metadata={ 8 | "vram_texture": false 9 | } 10 | 11 | [deps] 12 | 13 | source_file="res://AnimatedBtnIcon.png" 14 | dest_files=["res://.godot/imported/AnimatedBtnIcon.png-7832b89487ab8cf89f4bd4172b8bef33.ctex"] 15 | 16 | [params] 17 | 18 | compress/mode=0 19 | compress/high_quality=false 20 | compress/lossy_quality=0.7 21 | compress/hdr_compression=1 22 | compress/normal_map=0 23 | compress/channel_pack=0 24 | mipmaps/generate=false 25 | mipmaps/limit=-1 26 | roughness/mode=0 27 | roughness/src_normal="" 28 | process/fix_alpha_border=true 29 | process/premult_alpha=false 30 | process/normal_map_invert_y=false 31 | process/hdr_as_srgb=false 32 | process/hdr_clamp_exposure=false 33 | process/size_limit=0 34 | detect_3d/compress_to=1 35 | -------------------------------------------------------------------------------- /addons/animatedbutton/Button.svg.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://c3bureh7acevt" 6 | path="res://.godot/imported/Button.svg-ce4609c34a047e520472b7462e996a1c.ctex" 7 | metadata={ 8 | "vram_texture": false 9 | } 10 | 11 | [deps] 12 | 13 | source_file="res://addons/animatedbutton/Button.svg" 14 | dest_files=["res://.godot/imported/Button.svg-ce4609c34a047e520472b7462e996a1c.ctex"] 15 | 16 | [params] 17 | 18 | compress/mode=0 19 | compress/high_quality=false 20 | compress/lossy_quality=0.7 21 | compress/hdr_compression=1 22 | compress/normal_map=0 23 | compress/channel_pack=0 24 | mipmaps/generate=false 25 | mipmaps/limit=-1 26 | roughness/mode=0 27 | roughness/src_normal="" 28 | process/fix_alpha_border=true 29 | process/premult_alpha=false 30 | process/normal_map_invert_y=false 31 | process/hdr_as_srgb=false 32 | process/hdr_clamp_exposure=false 33 | process/size_limit=0 34 | detect_3d/compress_to=1 35 | svg/scale=1.0 36 | editor/scale_with_editor_scale=false 37 | editor/convert_colors_with_editor_theme=false 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Adil Shafiq 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Animated Button 2 | Custom button node that gives you some basic hover animations by default for scale and position. 3 | 4 | ![AnimatedButtonDemo](https://github.com/AdilDevStuff/AnimatedButton/assets/94475453/dc4ba99a-49cd-47c0-9ab1-2dfa59b6f79b) 5 | 6 | 7 | # How to use 8 | 1. Simply download the addon from release tab and copy it in your `res://addons` folder. 9 | 2. Then enable the plugin from the project settings. 10 | 3. And finally a new custom node called `AnimatedButton` will appear when creating a new node. 11 | 12 | # Properties Overview: 13 | `Duration` -> Its the duration for each animation 14 | 15 | `animate_scale` -> Check if you wanna animate the scale property of button. 16 | 17 | `animate_position` -> Check if you wanna animate the position property of button. 18 | 19 | `Scale Properties` -> `intensity` -> It is the scale hover value, set this according to your desired scale value. 20 | 21 | `Position Properties` -> `position_value` -> It is the position hover value, the button will animate to this position from its previous position. 22 | 23 | This custom node is still being worked on and is very basic as of now. Im going to add more stuff into it while keeping it simple and easy to use. 24 | 25 | # Ideas for future: 26 | - Add custom properties to animate. 27 | - Enter and exit animations like fade, pop etc. 28 | -------------------------------------------------------------------------------- /addons/animatedbutton/AnimatedButton.gd: -------------------------------------------------------------------------------- 1 | class_name AnimatedButton 2 | extends Button 3 | 4 | # ---------- Exported Variables ---------- # 5 | @export_range(0, 10, 0.001, "or_greater") var duration = 0.1 6 | 7 | @export var animate_scale: bool = true 8 | @export var animate_position: bool = false 9 | @export var transition_type: Tween.TransitionType 10 | 11 | @export_group("Scale Properties", "scale_") 12 | @export var scale_intensity: float = 1.1 13 | 14 | @export_group("Position Properties", "position_") 15 | @export var position_value: Vector2 = Vector2(0, -4) 16 | 17 | # ---------- Private Variables ---------- # 18 | 19 | var tween: Tween 20 | var btn_start_pos 21 | 22 | var is_btn_hovered: bool = false 23 | 24 | # ---------- Built-in Functions ---------- # 25 | 26 | func _ready() -> void: 27 | # Set the pivot offset at center 28 | pivot_offset = size / 2 29 | btn_start_pos = position 30 | 31 | func _process(delta: float) -> void: 32 | set_button_state() 33 | hover_scale_animation() 34 | hover_position_animation() 35 | 36 | # ---------- Signals ---------- # 37 | 38 | func set_button_state(): 39 | if self.is_hovered(): 40 | is_btn_hovered = true 41 | else: 42 | is_btn_hovered = false 43 | 44 | func hover_scale_animation(): 45 | if animate_scale: 46 | if is_btn_hovered: 47 | tweening(self, "scale", Vector2(scale_intensity, scale_intensity), duration) 48 | else: 49 | tweening(self, "scale", Vector2.ONE, duration) 50 | 51 | func hover_position_animation(): 52 | if animate_position: 53 | if is_btn_hovered: 54 | tweening(self, "position", btn_start_pos + Vector2(position_value.x, position_value.y), duration) 55 | else: 56 | tweening(self, "position", btn_start_pos, duration) 57 | 58 | # Global tween method 59 | func tweening(object: Object, property: NodePath, final_value: Variant, duration: float): 60 | tween = create_tween().set_parallel(true).set_trans(transition_type) 61 | tween.tween_property(object, property, final_value, duration) 62 | await tween.finished 63 | tween.kill() 64 | -------------------------------------------------------------------------------- /demo/demo.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=2 format=3 uid="uid://c8th54fejhpec"] 2 | 3 | [ext_resource type="Script" path="res://addons/animatedbutton/AnimatedButton.gd" id="1_voms5"] 4 | 5 | [node name="Demo" type="Control"] 6 | layout_mode = 3 7 | anchors_preset = 15 8 | anchor_right = 1.0 9 | anchor_bottom = 1.0 10 | grow_horizontal = 2 11 | grow_vertical = 2 12 | 13 | [node name="ScaleUp" type="Button" parent="."] 14 | layout_mode = 1 15 | anchors_preset = 8 16 | anchor_left = 0.5 17 | anchor_top = 0.5 18 | anchor_right = 0.5 19 | anchor_bottom = 0.5 20 | offset_left = -448.0 21 | offset_top = -100.0 22 | offset_right = -256.0 23 | offset_bottom = -38.0 24 | grow_horizontal = 2 25 | grow_vertical = 2 26 | text = "Scale Hover" 27 | script = ExtResource("1_voms5") 28 | 29 | [node name="ScaleDown" type="Button" parent="."] 30 | auto_translate_mode = 1 31 | layout_mode = 1 32 | anchors_preset = 8 33 | anchor_left = 0.5 34 | anchor_top = 0.5 35 | anchor_right = 0.5 36 | anchor_bottom = 0.5 37 | offset_left = -192.0 38 | offset_top = -100.0 39 | offset_bottom = -38.0 40 | grow_horizontal = 2 41 | grow_vertical = 2 42 | text = "Scale Hover" 43 | script = ExtResource("1_voms5") 44 | scale_intensity = 0.9 45 | 46 | [node name="PositionUp" type="Button" parent="."] 47 | auto_translate_mode = 1 48 | layout_mode = 1 49 | anchors_preset = 8 50 | anchor_left = 0.5 51 | anchor_top = 0.5 52 | anchor_right = 0.5 53 | anchor_bottom = 0.5 54 | offset_left = -448.0 55 | offset_top = 28.0 56 | offset_right = -256.0 57 | offset_bottom = 92.0 58 | grow_horizontal = 2 59 | grow_vertical = 2 60 | text = "Position Hover Up" 61 | script = ExtResource("1_voms5") 62 | animate_scale = false 63 | animate_position = true 64 | position_value = Vector2(0, -30) 65 | 66 | [node name="PositionDown" type="Button" parent="."] 67 | auto_translate_mode = 1 68 | layout_mode = 1 69 | anchors_preset = 8 70 | anchor_left = 0.5 71 | anchor_top = 0.5 72 | anchor_right = 0.5 73 | anchor_bottom = 0.5 74 | offset_left = -192.0 75 | offset_top = 28.0 76 | offset_bottom = 92.0 77 | grow_horizontal = 2 78 | grow_vertical = 2 79 | text = "Position Hover Down" 80 | script = ExtResource("1_voms5") 81 | animate_scale = false 82 | animate_position = true 83 | position_value = Vector2(0, 30) 84 | 85 | [node name="PositionLeft" type="Button" parent="."] 86 | auto_translate_mode = 1 87 | layout_mode = 1 88 | anchors_preset = 8 89 | anchor_left = 0.5 90 | anchor_top = 0.5 91 | anchor_right = 0.5 92 | anchor_bottom = 0.5 93 | offset_left = 64.0 94 | offset_top = 28.0 95 | offset_right = 256.0 96 | offset_bottom = 92.0 97 | grow_horizontal = 2 98 | grow_vertical = 2 99 | text = "Position Hover Left" 100 | script = ExtResource("1_voms5") 101 | animate_scale = false 102 | animate_position = true 103 | position_value = Vector2(-30, 0) 104 | 105 | [node name="PositionRight" type="Button" parent="."] 106 | auto_translate_mode = 1 107 | layout_mode = 1 108 | anchors_preset = 8 109 | anchor_left = 0.5 110 | anchor_top = 0.5 111 | anchor_right = 0.5 112 | anchor_bottom = 0.5 113 | offset_left = 320.0 114 | offset_top = 28.0 115 | offset_right = 512.0 116 | offset_bottom = 92.0 117 | grow_horizontal = 2 118 | grow_vertical = 2 119 | text = "Position Hover Right" 120 | script = ExtResource("1_voms5") 121 | animate_scale = false 122 | animate_position = true 123 | position_value = Vector2(30, 0) 124 | --------------------------------------------------------------------------------