Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

hey i was trying this out and i had a question, how do you type or include member variables to the Sup,Actor class?


Such as let healthvar = 100; and somehow access with the

let ActorGuy = new Sup.Actor("Test1")


and giving it that variable and accessing it later with stuff like Test1.healthvar += 1; (in some behavior script in an update function somewhere)


im very confused, also not sure where the main help thread for this software is.... im not used to typescript but trying to learn and I read how you declare objects in ECMA5 or whatever and it said you do

object = {

key: this,

key: that,

key: donelastkeyhere


}


and youd reference them within that way, but im not 100% sure. I'm trying to build a game just using code and C++ is giving me pains so i switched to typescript to see how it'd work and it seems to be similar in pain but without the awful linker issues.

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