Can I add/remove behaviors from objects at runtime w/ js?

For developers using the Construct 2 Javascript SDK

Post » Tue Sep 09, 2014 6:36 pm

Hello, back again with another question where I'm probably trying to make C2 do something it's not supposed to.

Is it possible to do something like:

mysprite= spawnfunctionthatreturnsSprite("someobject")

mysprite.addBehavior("mybehavior")

or even

mysprite.removeBehavior("mybehavior")

?
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730

Post » Wed Sep 10, 2014 12:06 am

I thought it is impossible.
Goodbye
B
111
S
28
G
295
Posts: 4,549
Reputation: 164,228

Post » Wed Sep 10, 2014 11:44 am

No, it's not possible. Why would you want to do that anyway? You can just enable or disable them at runtime instead.
Scirra Founder
B
408
S
242
G
92
Posts: 24,888
Reputation: 198,582

Post » Wed Sep 10, 2014 1:33 pm

AI patterns. Swapping behaviors in and out lends its self to it. Take RTS games for example, instead of having the behaviors for patrolling and defending crammed into the same behavior, swapping a patrol behavior for a defend behavior is pretty efficient and allows other AI routines to be swapped in.

You're right though, it is just as easy to enable/disable at run time. Thanks!
Developing Surolace, the survival role playing space game.

surolace-survival-role-playing-space-game_t116953
B
14
S
4
Posts: 303
Reputation: 1,730


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest