Hi! We had setup a subreddit for Superpowers help but it's not very convenient so we're in the process of setting up new forums right here on itch.io community, they'll go live pretty soon :) In the meantime, I can answer your question right here.
So just to give some context, actors are made of a few things:
- a name ("Test 1" for instance) and potentially a parent actor
- a transform (position, rotation, scale)
- a list of components
In order to attach some state and/or logic to an actor, you can use a behavior, which is a type of component (there are other types too, like a sprite renderer to name one).
// First we declare a new behavior class. // It can be used on any number of actors
class MyCustomBehavior extends Sup.Behavior { health = 100; takeDamage(amount) { this.health -= amount; } } Sup.registerBehavior(MyCustomBehavior); // Then we create an actor let actor = new Sup.Actor("Test 1"); // And we attach an instance of our behavior class to it
actor.addBehavior(MyCustomBehavior);
// Later on, if we want to access the health member variable on the behavior, we can write: Sup.log(actor.getBehavior(MyCustomBehavior).health);
// And we can call methods on the behavior like so: actor.getBehavior(MyCustomBehavior).takeDamage(5);
As you can see, using "someActor.getBehavior" is useful when your global initialization code needs to call methods or access member variables on a particular behavior. It is also useful if you have one behavior that needs to act on another actor's behavior, for instance, when an enemy hits a player, or vice versa.
We should probably add such an example to the documentation at docs.sparklinlabs.com/en/getting-started/variables...