godot_recipes
godot_recipes copied to clipboard
[Discussion] Touchscreen camera
Discussion for http://godotrecipes.com/2d/touchscreen_camera/
Thanks for this. Is there a way to implement this in python? I know how to make the camera pan and move, I just have a slight problem with trying to get pydroid to understand touch using PYX and drawing a d-pad and two-to-four buttons for actions and such. I have searched everywhere and keep bumping into bad examples. I did try using sdl2.touch.get_device from the Pygame reference website, but it looks like stereo instructions.
The pan code works great. The zoom code throws an error in Godot 3.4:
The line var drag_distance = events[0].position.distance_to(events[1].position)
gives an error of "Invalid get index '0' (on base: 'Dictionary')."
I fixed this by using events.values() to get the values as an array.
var drag_distance = events.values()[0].position.distance_to(events.values()[1].position)
The pan code works great. The zoom code throws an error in Godot 3.4:
The line
var drag_distance = events[0].position.distance_to(events[1].position)
gives an error of "Invalid get index '0' (on base: 'Dictionary')."I fixed this by using events.values() to get the values as an array.
var drag_distance = events.values()[0].position.distance_to(events.values()[1].position)
You can and should open a pull request to fix this - it's a really good point, since they slightly changed how input events work in 3.4.
I'll be honest, I dont know how to do that. My git hub knowledge is limited to: make a repo, git commit, and git push to main through the desktop app.
Note that you need to check the Current
checkbox on the camera in order for the camera to be active :)