Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Scene events #39

Closed
TheOrneryNerd opened this issue Sep 16, 2018 · 4 comments
Closed

[Question] Scene events #39

TheOrneryNerd opened this issue Sep 16, 2018 · 4 comments

Comments

@TheOrneryNerd
Copy link

Hi Elvis,

I was inspecting the samples project and I was wondering,
you have a single event handler for each type (keyboard, mouse, etc) per a scene - if you have 500 npcs of different types in 1 scene how do you manage their behavior (response) to each event that is sent in a organized and comfortable way?

I mean, how can you handle game logic easily this way?
if player attacks mob, where do you handle its response logic?
Or if a user clicks the right arrow button,
You do all the logic inside the scene’s handleKeyboardEvent method?

Shouldn’t the player input handling be encapsulated?

Thanks in advance

@elnormous
Copy link
Owner

For now, the only way to handle input is through event listeners. If you need to bind the input to a specific class, you need to write a wrapper yourself. I am still experimenting with different approaches. What do you suggest?

@TheOrneryNerd
Copy link
Author

Sorry for the delayed response.
First, thank you for answering me!
Second, I was thinking that it would be better to handle events in the actor level.

Handling events in the scene level could be quite messy as I can see it - especially if you're going to build a whole level with it - perhaps I see it wrong, I would be more than glad to see what you have in mind about that.

@elnormous
Copy link
Owner

You can handle them in actor level by adding event callbacks to your actor or component. Sending all events to ALL actors or components is really time-consuming (iterating through all the actors in the scene and calling methods for each of them) and we don't want this.

@TheOrneryNerd
Copy link
Author

Yeah, that's a trade of - but I think readability-wise might worth it.
Good job there! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants