if dragging:
moveGraph(event.screen_relative)```
dragging is set elsewhere with click events
```func moveGraph(distance:Vector2 = Vector2(0,0)):
graph._moveGraph(distance)```
^there is other code but it's unrelated to moving the graph or visuals so I'm excluding it
```func _moveGraph(distance: Vector2 = Vector2(0,0)):
var graphSizeX = get_global_rect().size.x
var graphSizeY = get_global_rect().size.y
graphPositionX += distance.x / graphScale / (screenSize.x / 1152.0)
graphPositionY += distance.y / graphScale / (screenSize.y / 648.0)
for i in get_children():
i.updatePosition(graphScale, graphPositionX, graphPositionY, graphSizeX, graphSizeY)```
```func updatePosition(graphScale:float = buttonScale, graphPositionX:float = 0, graphPositionY:float = 0, graphSizeX = 500, graphSizeY = 500):
buttonScale = graphScale
position.x = ((x+graphPositionX) * buttonScale) - (sizeX * buttonScale/2.0) + (graphSizeX/2.0)
position.y = (((y*-1)+graphPositionY) * buttonScale) - (sizeY * buttonScale/2.0) + (graphSizeY/2.0)
size.x = sizeX * buttonScale
size.y = sizeY * buttonScale```
position.x and y can be reduced to `position.x = (x+graphPositionX) * buttonScale` (you can also set buttonScale to 1) and the effect stays the same, just that the buttons spawn in the top left and are 1 pixel large if you do that
the buttons are children of the "graph" which is a panel with a clipping mask, inside of a chain of containers, I'm not sure if this matters though
I have to assume it's the viewport's aspect ratio causing it and not the panel it's a child of, because the panel starts with a strange ratio already
#Why is my code affected by aspect ratio?
1 messages · Page 1 of 1 (latest)
I have tried velocity, relative, and screen_velocity, but screen_relative seems to perform the best (if there's more modes to try, I am unaware)
which leads me to believe the problem lies here
graphPositionY += distance.y / (screenSize.y / 648.0)```
but I'm not sure why, since when shrinking the screen vertically, the width isn't changing
I think I know how to account for the aspect ratio, but as for the point of the post I'm concerned it might cause other problems later on if I don't understand why it acts like this and just decide to fix it
for now I'm going to change my code like this, which fixes it, but I'm still curious why I have to do this to begin with
Try event.relative
as I said here
ah sorry
I guess I didn't mention it by itself, but I've been told to try relative a few times but all it does is amplify the problem by about 3 times
and it also makes the above fix not work
What is screenSize?
And do you need all that math if you just want to move by the mouse delta?
the size of the screen in pixels
I'm not sure which math you're talking about, I showed above that the only technically required math for moving them was
graphPositionY += distance.y / (screenSize.y / 648.0)```
Everything else is for displacing the button to account for 0,0 normally being at the top left of the graph, buttons themselves have to be displaced by their size or they will be to the bottom right, and it has to account for the size so I can add scrolling
Why is that technically required though? Simply moving by event.relative would be always accurate
I dont understand how to answer the question
oh I think I understand now
I am not at my pc to test it, but since I already wrote it to work, it doesn't matter
I was told to try relative many times, but it took until now for me to see where I have to change the code to actually make that change work
(assuming what I'm understanding is correct)
Though, I still don't understand why this gets affected by aspect ratio
I understand why screen_relative is affected, but I don't understand why relative is affected too if you aren't ever changing screenSize
because the way I coded it was intended for screen_relative, normal relative doesnt work
and screenSize does change, when you change the size of the screen
So it's window size then?
You're dividing the window width by 1152 but your viewport width isn't 1152 when you change the ratio
Im not sure why the viewport has a different width than the window
if that's what you're saying
Maybe this will help you understand: https://docs.godotengine.org/en/stable/tutorials/rendering/multiple_resolutions.html
Expand sets the viewport's minimum size to whatever it is set to in project settings, but it will expand based on the ratio, so when you squeeze the window in the video, viewport width grows
Your code might work if you just remove the / (screenSize.x / 1152.0) part and use relative
yeah thats what I figured
The docs page you sent didnt help me understanding this though
this is what I wanted to know at least, so thank you