-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new value block: mouse_position #374
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screencast.from.2025-01-30.18-16-11.webm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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