Comments (5)
Thanks for looking into this. Most windows do separate keyboard input, but some games don't because they directly use Input
in physics process instead of the _input
functions. I'm not 100% sure if there's a way to stop a node from receiving input via the Input
singleton, even with that script.
from godotos.
Couldn't you send the signal focus_exited() when the focus is exited. Then some boolean variable could block input.
from godotos.
Then some boolean variable could block input.
I tried to do this in game_window.gd
using node.set_process_input(false)
, but it turns out that only disables the _input()
function and doesn't stop it from using the Input singleton, which means games will probably use input anyways in process functions. As far as I know there isn't really a catch-all way to disable input.
from godotos.
Then some boolean variable could block input.
I tried to do this in
game_window.gd
usingnode.set_process_input(false)
, but it turns out that only disables the_input()
function and doesn't stop it from using the Input singleton, which means games will probably use input anyways in process functions. As far as I know there isn't really a catch-all way to disable input.
My solution
My solution is to split _process(delta:float)
(or _physics_process(delta:float)
) into two parts:
- The functions which uses
Input
. - The functions which does not use
Input
.
The 2nd part will run only if it is focused. And everything works just fine.
Example
Something like this:
extends StateMachine
class_name CompatibleStateMachine
func _ready():
for child_node in get_children():
if child_node is State:
all_states[child_node.name] = child_node
child_node.state_changed.connect(on_child_state_changed)
if initial_state:
initial_state.enter()
current_state = initial_state
### 1st part ###
func _input(event: InputEvent):
if current_state:
current_state.handle_input_event(event)
func _unhandled_input(event: InputEvent):
if current_state:
current_state.handle_remaining_input_event(event)
func _process(delta: float):
if current_state:
current_state.update_frame(delta)
func _physics_process(delta: float):
if current_state:
current_state.update_physics(delta)
### 2nd part ###
func handle_input_event(event: InputEvent):
if current_state:
current_state.handle_input_event(event)
func handle_remaining_input_event(event: InputEvent):
if current_state:
current_state.handle_remaining_input_event(event)
func update_per_frame(delta: float):
if current_state:
current_state.update_per_frame(delta)
func update_per_physics(delta: float):
if current_state:
current_state.update_per_physics(delta)
Upon is a state machine which is designed to be compatible with
InputManager
I metioned.Sorry that I can not share all the code since the project is confidential for now.
from godotos.
State example of walk:
extends CompatibleState
class_name PlayerState
@onready var machine = $".."
@onready var player = $"../.."
func enter():
pass
func exit():
pass
func handle_input_event(event: InputEvent):
pass
func handle_remaining_input_event(event: InputEvent):
pass
func update_per_frame(delta: float):
pass
func update_per_physics(delta: float):
if player.is_on_floor():
elif player.direction:
if Input.is_action_pressed("Sprint"):
machine.change_state.emit(self, "Run")
else:
machine.change_state.emit(self, "Walk")
else:
machine.change_state.emit(self, "Idle")
else:
machine.change_state.emit(self, "Air")
func handle_input_event(event: InputEvent):
pass
func handle_remaining_input_event(event: InputEvent):
pass
func update_per_frame(delta: float):
pass
func update_per_physics(delta: float):
if player.is_on_floor():
if Input.is_action_pressed("Down"):
machine.change_state.emit(self, "Down")
extends PlayerState
func enter():
player.appearance.walk_run(player.velocity.length())
func exit():
player.acceleration = player.walk_acceleration
func update_per_frame(delta: float):
origin.handle_camera_shake(delta)
func update_per_physics(delta: float):
player.acceleration = lerp(player.acceleration, player.walk_acceleration, delta * player.acceleration_change_rate)
if player.direction:
player.velocity += (player.direction * player.acceleration * delta)
player.appearance.walk_run(player.velocity.length())
if player.is_on_floor():
if Input.is_action_pressed("Down"):
if player.velocity.length() > player.slide_start_threshold:
machine.change_state.emit(self, "Slide")
else:
machine.change_state.emit(self, "Crouch")
elif Input.is_action_just_released("Up"):
machine.change_state.emit(self, "Jump")
Hope these help. :-)
from godotos.
Related Issues (13)
- On Linux make it possible to use it as a DE HOT 3
- Duplicate files are not overwritten HOT 1
- Directory Traversal Exploit HOT 3
- Add Chromium as a browser (via CEF)? HOT 3
- Add Doom 1 pls HOT 5
- Game window resolution is tied to screen scale
- New standard wallpapers HOT 2
- Add 3d game supporting system(like game from Godot) and GodotOS updating HOT 1
- Adding HTML/CSS/JS supporting HOT 1
- Add Terminal and terminal command like ipconfig(on Windows), echo, cd and etc.
- wordwrap for text viewer HOT 2
- Adding files that aren't local HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godotos.