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.
B
108
S
26
G
267
Posts: 4,455
Reputation: 149,745

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
395
S
231
G
88
Posts: 24,367
Reputation: 193,694

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 0 guests