0 votes

Hello,

I would like to allow zooming in and out on cellphone. What signals should I look for? I guess zooming in would be triggered by two fingers getting closer on the screen, while zooming out would be triggered by two fingers getting farther away.

Thank you for your help.

asked May 1 in Engine by Thrallherd (19 points)

2 Answers

0 votes

InputEventScreenTouch has the index property so you should be able to check the index number, get the two positions and get the length of position 0 - position 1

var positions : Array = [Vector2(), Vector2()]

func _input(event):
    if event is InputEventScreenTouch:
        positions[event.index] = event.position
        if event.index == 1:
            var zoom_amount = (positions[0] - positions[1]).length()

(I've not tested this though)

answered May 1 by Magso (2,851 points)

Thank you for your help. Your reply is in alignment with the other reply :)

+1 vote

You might find this helpful: http://godotrecipes.com/2d/touchscreen_camera/

answered May 2 by kidscancode (17,702 points)

Thank you for your reply. Unfortunately, even though I enabled "Emulate Touch From Mouse", the camera doesn't move when I click around the target. I'm not sure what's wrong. I did specify a target.

Make sure you don't have a Control node intercepting the mouse/touch events.

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.