superpowers / superpowers-game

:video_game: Make 2D and 3D games in live collaboration with Superpowers
http://superpowers-html5.com/
Other
401 stars 93 forks source link

cannot access more than one actor component #110

Open ken-sands opened 8 years ago

ken-sands commented 8 years ago

The edtior lets us add more than one of any component type to an actor, ie a single actor can have 2 textrenderer and they display fine and work however there seems no way to access them. could we have a getComponents() or getComponent(name) or getTextRenderers() / GetSpriteRenderers() etc functions?

JuDelCo commented 8 years ago

A bit quirk, but maybe using this? :

(myActor as any).__inner.components

See: https://github.com/superpowers/superpowers-game/wiki

ken-sands commented 8 years ago

Ahh sweet! thanks for that. Saves me having way more actors than I wanted!

Still I feel the issue stands, we should probably have a sensible way to the component list.

JuDelCo commented 8 years ago

Yes, this should be a feature

elisee commented 8 years ago

Do you have a concrete use case for having multiple sprite renderers or multiple text renderers on a single actor? They'll overlap since they won't have their own transforms. Seems rarely useful if ever?

ken-sands commented 8 years ago

It just seemed intuitive to me to do it, and nothing suggested I shouldn't. The first thing I used it for was to do text with a kind of pop out shadow. (size 32 font with size 30 on top) so the text stood out, but then found I couldn't change the text for both due to the issue. For the sprites it'd let me build up a character from various body parts very easily. (being able to set the sprite origin would help along with that) it just seemed overkill to create an actor for each as children of one actor to give them position and physics and such. If the right way is to enforce child actors that's cool but then the issue becomes 'it should't allow us to create more than one of the same component in the editor'

ken-sands commented 8 years ago

Okay, this is my second case explained a bit, lets say I want to make something space invader like but I want lots of variation in my enemies, I could spend days creating huge sprite sheets of enemies or I could be a bit clever and split my bad guys into say 4 parts, then If I create say 20 versions of each of those parts I have.... like... 160'000 possible bad guys! or something like that. That's great. now if I throw all 4 in as components to one actor it's just an array it goes through per actor to render each bad guy, that doesn't seem too expensive. however if I would need to create an actor for each one it would mean my scene that had say 50 bad guys on it has gone from 50 bad guy actors to 250. (1 per bad guy plus one child for each sprite renderer) each of those will need to go through the code that checks for position and transform etc etc etc. to me that seems like a computationally expensive process.

2 bad guys... way too much art work...

image

multi component I already have 16 bad guys!....

image

ken-sands commented 8 years ago

If I was writing my own game engine for the above example I'd generate a selection of sprites from the components before the game / level started and solve the problem that way but it's about working within the limits of what we have.

Hope all that makes sense.