Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

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...

Ok, if I'm understanding this right, to get a behavior it must be printed to superpowers log using Sup.Log(<value retrieved somewhere stored>) which can be an actor so Sup.log(<ActiorName>.getBehavior(<BehaviorName>).<VariableName>); and lets say I wanted to run update tests against this value or another value (like its position overlapping a damaging tile) I would run positional checks in code against the Superpowers Actor class (Sup.Actor which I created as "Test1" for instance) and then in a if conditional


if Sup.log(Sup.log(actor.getBehavior(MyCustomBehavior).CustomX) == Sup.log(Sup.log(EnemyActor?.getBehavior(MyCustomBehavior).CustomX) // Can the engine differentiate collisions and run these functions from each object?

{

let tempVar = Sup.log(actor.getBehavior(MyCustomBehavior).health);

actor.getBehavior().<custom_method>(param0, etc);


//Define method here>>>>>>???


//Or is the method a script that is loaded before this is run or after?

}


sorry for the newbie questions, Ive been learning programming but working with pre-built engine environments is just as confusing to me sometimes but is usually far less work which is why I am trying to learn to use everything I can. For instance game maker/unity work alot like this but still sometime confuses me.

(1 edit)

No, you don't need to use Sup.log! It was an example, to show how to do something concrete after getting a behavior (in this case, Sup.log displays a member variable's value in the browser's development tools, but you could be doing any number of things instead).

If you haven't already, looking at some of the demo projects might help: http://docs.sparklinlabs.com/en/resources/demo-pro... and https://bitbucket.org/sparklinlabs/profile/reposit...

Regarding collisions, there is a built-in axis-aligned bounding box collision system called ArcadePhysics2D. You can find a tutorial here: http://docs.sparklinlabs.com/en/tutorials/collisio...