Skip to content

How to determine the type of an InputEvent? #38

Closed Answered by Splizard
Ullanar asked this question in Q&A
Discussion options

You must be logged in to vote

You can switch on the underlying event type and access the derived godot class like this:
(I also recommend capturing Input and tmp variables and using the named enum values to make the code more concise and readable)

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.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Ullanar
Comment options

@Splizard
Comment options

Answer selected by Splizard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #37 on July 06, 2024 21:08.