Conversation
| code_template = "(func (): var transform: Transform2D = get_viewport_transform(); var scale: Vector2 = transform.get_scale(); return | ||
| get_viewport().get_mouse_position() * scale ).call() | ||
|
|
||
|
|
||
| " |
There was a problem hiding this comment.
Why not write this as:
| code_template = "(func (): var transform: Transform2D = get_viewport_transform(); var scale: Vector2 = transform.get_scale(); return | |
| get_viewport().get_mouse_position() * scale ).call() | |
| " | |
| code_template = "get_viewport().get_mouse_position() * get_viewport_transport().get_scale()" |
I tried the following block program for the left paddle in pong:
The generated script is:
extends SimpleCharacter
func _process(delta):
position = ((func (): var transform: Transform2D = get_viewport_transform(); var scale: Vector2 = transform.get_scale(); return
get_viewport().get_mouse_position() * scale ).call()
)
And this fails to start with:
Parser Error: Expected closing ")" after grouping expression.
If I delete all the trailing newlines in this template, the generated code becomes:
extends SimpleCharacter
func _process(delta):
position = ((func (): var transform: Transform2D = get_viewport_transform(); var scale: Vector2 = transform.get_scale(); return
get_viewport().get_mouse_position() * scale ).call())
but the error is the same. Maybe it's the newline after return, how did that get in there...
Godot itself keeps crashing when I try to save/run changes...
When I change the template to what I proposed above, the game runs, but the scaling is wrong. It could be that my program is wrong...
There was a problem hiding this comment.
Screencast.from.2025-01-30.18-16-11.webm
There was a problem hiding this comment.
Maybe we need to add - get_viewport_transform().origin? Thanks for reminding me that Pong is the perfect way to test this, as it has the viewport scaled.
Under category Input. Using the current node CanvasItem.get_global_mouse_position() which considers viewport offset and scale. Fix #373
b584095 to
d55f2cf
Compare
|
@wjt this was actually easier, using |

Under category Input. Considering the viewport scale as explained in [1]. The same thing we do for the viewport_width and other blocks.
[1] https://docs.godotengine.org/en/stable/tutorials/inputs/mouse_and_input_coordinates.html
Fix #373