Skip to content

Commit 92dc236

Browse files
committed
feat: 增加了点击爆炸视觉特效
1 parent f154c1a commit 92dc236

File tree

6 files changed

+77
-25
lines changed

6 files changed

+77
-25
lines changed

assets/explosion.png

540 Bytes
Loading

assets/explosion.png.import

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://cx2ggbdmli6yb"
6+
path="res://.godot/imported/explosion.png-3d70b655f829d2ec362997bd3be8e3ae.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://assets/explosion.png"
14+
dest_files=["res://.godot/imported/explosion.png-3d70b655f829d2ec362997bd3be8e3ae.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

ball.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func _ready():
3030
# 点击
3131
func _on_Area2D_input_event(_viewport, event, _shape_idx):
3232
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
33-
emit_signal("ball_clicked")
33+
emit_signal("ball_clicked", position, scale)
3434
queue_free()
3535

3636

ball_explosion.tscn

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
1-
[gd_scene load_steps=9 format=3 uid="uid://cfhnxg4deer84"]
1+
[gd_scene load_steps=10 format=3 uid="uid://cfhnxg4deer84"]
22

3-
[ext_resource type="Texture2D" uid="uid://bgthx0c001b41" path="res://assets/ball_explosion.png" id="1_7pb6g"]
3+
[ext_resource type="Texture2D" uid="uid://cx2ggbdmli6yb" path="res://assets/explosion.png" id="1_nse4d"]
4+
[ext_resource type="Script" path="res://ball_explosion_animate.gd" id="2_27dbk"]
45

5-
[sub_resource type="AtlasTexture" id="AtlasTexture_3ti85"]
6-
atlas = ExtResource("1_7pb6g")
6+
[sub_resource type="AtlasTexture" id="AtlasTexture_t4wxn"]
7+
atlas = ExtResource("1_nse4d")
78
region = Rect2(0, 0, 20, 20)
89

9-
[sub_resource type="AtlasTexture" id="AtlasTexture_ckv16"]
10-
atlas = ExtResource("1_7pb6g")
10+
[sub_resource type="AtlasTexture" id="AtlasTexture_e1ytu"]
11+
atlas = ExtResource("1_nse4d")
1112
region = Rect2(20, 0, 20, 20)
1213

13-
[sub_resource type="AtlasTexture" id="AtlasTexture_j2q1p"]
14-
atlas = ExtResource("1_7pb6g")
14+
[sub_resource type="AtlasTexture" id="AtlasTexture_b2pcb"]
15+
atlas = ExtResource("1_nse4d")
1516
region = Rect2(40, 0, 20, 20)
1617

17-
[sub_resource type="AtlasTexture" id="AtlasTexture_5tf34"]
18-
atlas = ExtResource("1_7pb6g")
18+
[sub_resource type="AtlasTexture" id="AtlasTexture_rn1yp"]
19+
atlas = ExtResource("1_nse4d")
1920
region = Rect2(60, 0, 20, 20)
2021

21-
[sub_resource type="AtlasTexture" id="AtlasTexture_37ewm"]
22-
atlas = ExtResource("1_7pb6g")
22+
[sub_resource type="AtlasTexture" id="AtlasTexture_8xjnp"]
23+
atlas = ExtResource("1_nse4d")
2324
region = Rect2(80, 0, 20, 20)
2425

25-
[sub_resource type="AtlasTexture" id="AtlasTexture_uo3mc"]
26-
atlas = ExtResource("1_7pb6g")
26+
[sub_resource type="AtlasTexture" id="AtlasTexture_i5xxp"]
27+
atlas = ExtResource("1_nse4d")
2728
region = Rect2(100, 0, 20, 20)
2829

2930
[sub_resource type="SpriteFrames" id="SpriteFrames_a1jpm"]
31+
resource_name = "explosion"
3032
animations = [{
3133
"frames": [{
3234
"duration": 1.0,
33-
"texture": SubResource("AtlasTexture_3ti85")
35+
"texture": SubResource("AtlasTexture_t4wxn")
3436
}, {
3537
"duration": 1.0,
36-
"texture": SubResource("AtlasTexture_ckv16")
38+
"texture": SubResource("AtlasTexture_e1ytu")
3739
}, {
3840
"duration": 1.0,
39-
"texture": SubResource("AtlasTexture_j2q1p")
41+
"texture": SubResource("AtlasTexture_b2pcb")
4042
}, {
4143
"duration": 1.0,
42-
"texture": SubResource("AtlasTexture_5tf34")
44+
"texture": SubResource("AtlasTexture_rn1yp")
4345
}, {
4446
"duration": 1.0,
45-
"texture": SubResource("AtlasTexture_37ewm")
47+
"texture": SubResource("AtlasTexture_8xjnp")
4648
}, {
4749
"duration": 1.0,
48-
"texture": SubResource("AtlasTexture_uo3mc")
50+
"texture": SubResource("AtlasTexture_i5xxp")
4951
}],
50-
"loop": true,
51-
"name": &"default",
52+
"loop": false,
53+
"name": &"explode",
5254
"speed": 30.0
5355
}]
5456

@@ -59,3 +61,5 @@ texture_filter = 1
5961
texture_repeat = 1
6062
scale = Vector2(11.3, 11.3)
6163
sprite_frames = SubResource("SpriteFrames_a1jpm")
64+
animation = &"explode"
65+
script = ExtResource("2_27dbk")

ball_explosion_animate.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends AnimatedSprite2D
2+
3+
4+
# Called when the node enters the scene tree for the first time.
5+
func _ready():
6+
connect("animation_finished", _on_animation_finished)
7+
play("explode", 1.0, false) # 如果未启用 Autoplay 时使用
8+
9+
func _on_animation_finished():
10+
get_parent().queue_free() # 动画完成后自动销毁父节点
11+

main.gd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func update_ui():
4545

4646

4747
# 点击击杀逻辑
48-
func _on_ball_clicked():
48+
func _on_ball_clicked(ball_dead_position, ball_dead_scale):
4949
if !game_active:
5050
return
5151
score += 1
@@ -55,7 +55,10 @@ func _on_ball_clicked():
5555
# 增加爆炸效果
5656
var ball_explosion = ball_explosion_scene.instantiate()
5757
add_child(ball_explosion)
58-
58+
ball_explosion.position = ball_dead_position
59+
ball_explosion.scale = ball_dead_scale
60+
# var animated_sprite = ball_explosion.get_node("AnimatedSprite2D")
61+
# animated_sprite.play("explode")
5962
# 产生新的碎片
6063
#var split = split_scene.instantiate()
6164
#add_child(split)

0 commit comments

Comments
 (0)