1
Fork 0
mirror of https://github.com/Steffo99/looping-for-loops.git synced 2024-11-25 09:34:22 +00:00

❇️ Implement GameButtons (clickable)

This commit is contained in:
Steffo 2020-10-04 18:17:54 +02:00
parent c8342b9e1c
commit a7f3f9302c
7 changed files with 109 additions and 3 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=8 format=2]
[ext_resource path="res://Objects/SpecialObjects/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://Objects/SpecialObjects/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://Objects/SpecialObjects/Conductor.tscn" type="PackedScene" id=2] [ext_resource path="res://Objects/SpecialObjects/Conductor.tscn" type="PackedScene" id=2]
@ -6,6 +6,7 @@
[ext_resource path="res://Objects/SpecialObjects/SingleScreenWalls.tscn" type="PackedScene" id=4] [ext_resource path="res://Objects/SpecialObjects/SingleScreenWalls.tscn" type="PackedScene" id=4]
[ext_resource path="res://Objects/SpecialObjects/Wrapper.tscn" type="PackedScene" id=5] [ext_resource path="res://Objects/SpecialObjects/Wrapper.tscn" type="PackedScene" id=5]
[ext_resource path="res://Objects/ScrollingObjects/ScrollingBlock.tscn" type="PackedScene" id=6] [ext_resource path="res://Objects/ScrollingObjects/ScrollingBlock.tscn" type="PackedScene" id=6]
[ext_resource path="res://Objects/ScrollingObjects/Buttons/GameButton.tscn" type="PackedScene" id=7]
[node name="Main" type="Node2D"] [node name="Main" type="Node2D"]
__meta__ = { __meta__ = {
@ -20,7 +21,6 @@ __meta__ = {
[node name="ConveyorBelt" parent="." instance=ExtResource( 3 )] [node name="ConveyorBelt" parent="." instance=ExtResource( 3 )]
position = Vector2( 640, 700 ) position = Vector2( 640, 700 )
cb_speed = 100.0
[node name="Player" parent="." instance=ExtResource( 1 )] [node name="Player" parent="." instance=ExtResource( 1 )]
position = Vector2( 340, 500 ) position = Vector2( 340, 500 )
@ -33,3 +33,6 @@ position = Vector2( 840, 660 )
[node name="ScrollingBlock3" parent="." instance=ExtResource( 6 )] [node name="ScrollingBlock3" parent="." instance=ExtResource( 6 )]
position = Vector2( 980, 660 ) position = Vector2( 980, 660 )
[node name="GameButton" parent="." instance=ExtResource( 7 )]
position = Vector2( 1000, 480 )

View file

@ -0,0 +1,32 @@
extends Node2D
class_name GameButton
export(Color, RGB) var color: Color = Color.white setget set_color
export(Texture) var active_sprite: Texture = null
export(Texture) var pressed_sprite: Texture = null
export(bool) var is_active: bool = true setget set_active
signal clicked
func _ready():
set_color(color)
set_active(is_active)
func set_color(value):
color = value
$Sprite.modulate = value
func set_active(value):
is_active = value
if value:
$Sprite.texture = active_sprite
else:
$Sprite.texture = pressed_sprite
func _on_GameButton_input_event(viewport: Viewport, event: InputEvent, shape_idx: int):
if is_active and event.is_pressed():
emit_signal("clicked")

View file

@ -0,0 +1,29 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://Sprites/button.png" type="Texture" id=1]
[ext_resource path="res://Objects/ScrollingObjects/Buttons/GameButton.gd" type="Script" id=2]
[ext_resource path="res://Objects/ScrollingObjects/Utilities/ConveyorScrollParent.tscn" type="PackedScene" id=3]
[ext_resource path="res://Objects/ScrollingObjects/Utilities/WrapParent.tscn" type="PackedScene" id=4]
[ext_resource path="res://Sprites/button_pressed.png" type="Texture" id=5]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 20, 20 )
[node name="GameButton" type="Area2D"]
collision_layer = 8
collision_mask = 2147483648
script = ExtResource( 2 )
active_sprite = ExtResource( 1 )
pressed_sprite = ExtResource( 5 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
[node name="ConveyorScrollParent" parent="." instance=ExtResource( 3 )]
[node name="WrapParent" parent="." instance=ExtResource( 4 )]
[connection signal="input_event" from="." to="." method="_on_GameButton_input_event"]

View file

@ -3,7 +3,6 @@
[ext_resource path="res://Sprites/player_danny_devito.png" type="Texture" id=1] [ext_resource path="res://Sprites/player_danny_devito.png" type="Texture" id=1]
[ext_resource path="res://Objects/SpecialObjects/Player.gd" type="Script" id=2] [ext_resource path="res://Objects/SpecialObjects/Player.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 16 ) extents = Vector2( 16, 16 )

BIN
Sprites/button_pressed.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/button_pressed.png-36b20c9854df3037cade8d1ea8f243a6.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/button_pressed.png"
dest_files=[ "res://.import/button_pressed.png-36b20c9854df3037cade8d1ea8f243a6.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View file

@ -29,6 +29,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://Objects/ScrollingObjects/Utilities/ConveyorScrollParent.gd" "path": "res://Objects/ScrollingObjects/Utilities/ConveyorScrollParent.gd"
}, { }, {
"base": "Node2D",
"class": "GameButton",
"language": "GDScript",
"path": "res://Objects/ScrollingObjects/Buttons/GameButton.gd"
}, {
"base": "KinematicBody2D", "base": "KinematicBody2D",
"class": "Player", "class": "Player",
"language": "GDScript", "language": "GDScript",
@ -64,6 +69,7 @@ _global_script_class_icons={
"Conductor": "", "Conductor": "",
"ConveyorBelt": "", "ConveyorBelt": "",
"ConveyorScrollParent": "", "ConveyorScrollParent": "",
"GameButton": "",
"Player": "", "Player": "",
"Press": "", "Press": "",
"ScrollParent": "", "ScrollParent": "",