bberak / react-game-engine

A lightweight Game Engine for the web (React) ๐Ÿ•นโšก๐ŸŽฎ
MIT License
413 stars 24 forks source link

Remove components from game loop! #21

Closed rstp-god closed 2 years ago

rstp-god commented 2 years ago

Hello, i want to delete some components from gameloop, How can i do this? Try delete entities[name] but they still inside. So { renderer: null } still working, but components stop displays not deleted from gameloop. I think this affect at perfomace. Ty 4 answer!

bberak commented 2 years ago

Hi @azirb,

Where do you have this piece of code?

delete entities[name]

Is it in a system or somewhere else? Can you share some more of your code to give me more context?

rstp-god commented 2 years ago

Yep tried inside systems! But already work, i just see my mistake. Btw can systems use only one entities ? Or every system must return {...entities}?

bberak commented 2 years ago

Glad you sorted out this problem @azirb ๐Ÿ™

A system must return all the entities that it wants the next system to get access to.. So typically you would be returning them all:

delete entities[name]

return { ...entities }; // Returning a new object

// or

return entities; // Returning the  same object