Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Inqui |
Currently, I’m creating a level menu where user should be able to choose the level to play. Nodes hierarchy:
VBoxContainer
-- Label
-- ScrollContainer
---- VBoxContainer
------ GridContainer1 (easy levels)
------ GridContainer2 (medium levels)
------ GridContainer3 (hard levels)
Each grid container has a bunch of buttons generated from this code:
private static void SetLevels(in GridContainer container) {
for (var i = 0; i < 50; i++) {
var button = new Button {
Text = (i + 1).ToString(),
SizeFlagsHorizontal = (int) SizeFlags.ExpandFill,
SizeFlagsVertical = (int) SizeFlags.ExpandFill,
FocusMode = FocusModeEnum.None,
MouseFilter = MouseFilterEnum.Pass
};
button.Set("custom_fonts/font", ButtonFont);
// Workaround for SetScript weird behaviour. See https://github.com/godotengine/godot/issues/31994
var iId = button.GetInstanceId();
button.SetScript(ButtonScript);
var completeButton = (Button) GD.InstanceFromId(iId);
container.AddChild(completeButton);
}
}
And ButtonScript
is a simple class with one connection:
internal class LevelButton: Button {
public override void _Ready() {
Connect("pressed", this, nameof(OnPressed));
}
public void OnPressed() {
GD.Print($"{Text}: pressed");
}
}
The problem is that on a mobile device (Android in my case) I cannot press any level button without high precision. In most cases, my touch will be detected as a scroll event (drag). PC doesn’t have such problem.
I’ve tried to change step and customStep in the VScrollBar
instance from ScrollContainer
and it works as expected but it doesn’t fix my problem.
My only guess would be to adjust the scroll_deadzone
propery of the ScrollContainer
. I would try to set it to something extraordinarily high like your screen size and see if you’re still having your problem.
timothybrentwood | 2021-05-03 18:55
Thanks! This is exactly what I need. I think I misunderstood the scroll_deadzone
property.
Inqui | 2021-05-05 16:44