From 39d476ec76742666ad2f55706c630ce1a81dbd1a Mon Sep 17 00:00:00 2001 From: freewu32 <2217332562@qq.com> Date: Thu, 3 Sep 2020 23:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=AA=E7=89=A9=E5=9B=BE=E9=89=B4=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=A7=A6=E6=91=B8=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Main.tscn | 14 +++++++++++--- src/utils/TouchScrollContainer.gd | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/utils/TouchScrollContainer.gd diff --git a/Main.tscn b/Main.tscn index 5711258..b2a6f06 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=28 format=2] +[gd_scene load_steps=29 format=2] [ext_resource path="res://src/levels/Level1.tscn" type="PackedScene" id=1] +[ext_resource path="res://src/utils/TouchScrollContainer.gd" type="Script" id=2] [ext_resource path="res://assets/sounds/bgm.ogg" type="AudioStream" id=5] [ext_resource path="res://assets/images/ground.png" type="Texture" id=6] [ext_resource path="res://assets/images/icons_old.png" type="Texture" id=7] @@ -425,16 +426,23 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -margin_left = -208.0 +margin_left = -200.0 margin_top = -200.0 -margin_right = 232.0 +margin_right = 197.0 margin_bottom = 152.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 scroll_horizontal_enabled = false +script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false } [node name="VBoxContainer" type="VBoxContainer" parent="HUD/BookDialog/ScrollContainer"] +margin_right = 397.0 +margin_bottom = 352.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 __meta__ = { "_edit_use_anchors_": false } diff --git a/src/utils/TouchScrollContainer.gd b/src/utils/TouchScrollContainer.gd new file mode 100644 index 0000000..8230892 --- /dev/null +++ b/src/utils/TouchScrollContainer.gd @@ -0,0 +1,23 @@ +extends ScrollContainer + +var isDrag = false +var startPos = 0 +var dragDir = 0 + +func _input(event): + if event is InputEventMouseButton: + if event.button_index != BUTTON_LEFT: + return + if event.is_pressed(): + isDrag = true + startPos = event.position.y + print("pressed") + if !event.is_pressed(): + isDrag = false + startPos = 0 + print("not pressed") + if event is InputEventMouseMotion and isDrag: + var offset = event.position.y - startPos + self.scroll_vertical -= offset + startPos = event.position.y + print("drag")