+1 vote

hello everyone i am using this script to scroll my TextEdit node in android but it scrolls way too fast. Can you help me to slow its scroll speed?

extends TextEdit

# Allows you to scroll a scroll container by dragging.
# Includes momentum.
# Make sure Mouse->Filter is Ignore.
var swiping = false
var swipe_start
var swipe_mouse_start
var swipe_mouse_times = []
var swipe_mouse_positions = []

func _ready():
    mouse_filter = Control.MOUSE_FILTER_IGNORE

func _input(ev):
    if ev is InputEventMouseButton:
        if ev.pressed:
            swiping = true
            swipe_start = Vector2(get_h_scroll(), get_v_scroll())
            swipe_mouse_start = ev.position
            swipe_mouse_times = [OS.get_ticks_msec()]
            swipe_mouse_positions = [swipe_mouse_start]
            var source = Vector2(get_h_scroll(), get_v_scroll())
            var idx = swipe_mouse_times.size() - 1
            var now = OS.get_ticks_msec()
            var cutoff = now - 100
            for i in range(swipe_mouse_times.size() - 1, -1, -1):
                if swipe_mouse_times[i] >= cutoff: idx = i
                else: break
            var flick_start = swipe_mouse_positions[idx]
            var flick_dur = min(0.3, (ev.position - flick_start).length() / 1000)
            if flick_dur > 0.0:
                var tween = Tween.new()
                var delta = ev.position - flick_start
                var target = source - delta * flick_dur * 15.0
                tween.interpolate_method(self, 'set_h_scroll', source.x, target.x, flick_dur, Tween.TRANS_LINEAR, Tween.EASE_OUT)
                tween.interpolate_method(self, 'set_v_scroll', source.y, target.y, flick_dur, Tween.TRANS_LINEAR, Tween.EASE_OUT)
                tween.interpolate_callback(tween, flick_dur, 'queue_free')
            swiping = false
    elif swiping and ev is InputEventMouseMotion:
        var delta = ev.position - swipe_mouse_start
        set_h_scroll(swipe_start.x - delta.x)
        set_v_scroll(swipe_start.y - delta.y)
in Engine by (44 points)

I don't really know why the TextEdit node is scrolling quickly for you. It may be due to all of this happening in the _input() function. Maybe some of this code has to be placed in the _process() function?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.