-
Hi! Here is simple code snippet from examples func (p *Player) Process(delta gd.Float) {
Input := gd.Input(p.Temporary)
//...
}
So i want to make function like func (p *Player) HandleInput(event gd.InputEvent) {
// trying to handle mouse modes
if event.AsInputEvent().IsActionPressed(p.Temporary.StringName("ui_cancel"), true, true) {
mouseMode := gd.Input(p.Temporary).GetMouseMode()
if mouseMode == gd.InputMouseMode(0) {
gd.Input(p.Temporary).SetMouseMode(gd.InputMouseMode(1))
} else {
gd.Input(p.Temporary).SetMouseMode(gd.InputMouseMode(0))
}
}
// rest of strange code to collect movements
} How can I get that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can switch on the underlying event type and access the derived godot class like this: func (p *Player) HandleInput(event gd.InputEvent) {
var (
tmp = p.Temporary
Input = gd.Input(tmp)
)
if event.IsActionPressed(tmp.StringName("ui_cancel"), true, true) {
mouseMode := Input.GetMouseMode()
if mouseMode == gd.InputMouseModeVisible {
Input.SetMouseMode(gd.InputMouseModeHidden)
} else {
Input.SetMouseMode(gd.InputMouseModeVisible)
}
}
// Switch on the underlying event type.
switch event := tmp.Variant(event).Interface(tmp).(type) {
case gd.InputEventMouseMotion:
case gd.InputEventMouseButton:
}
} I understand it's not obvious how to do the type switch, so I appreciate you reporting your experience here and I will be considering ideas on how to make this more intuitive. |
Beta Was this translation helpful? Give feedback.
You can switch on the underlying event type and access the derived godot class like this:
(I also recommend capturing
Input
andtmp
variables and using the named enum values to make the code more concise and readable)