Instances of a plugin that contains sprites

For developers using the Construct 2 Javascript SDK

Post » Sun May 04, 2014 7:37 pm

I'm not sure what's the best way to approach it, the way I have in mind seems too inconvenient.

I'd like to have a plugin that contains and controls sprites. I'd like to have a few instances of that plugin.

Should I create a couple of sprites for each instance of the plugin and pass them to it? (and have a few instances of the plugin manually as well)

Is that how I should approach it in Construct 2? Isn't there a more convenient way? Perhaps somehow create instances of sprite dynamically inside of a dynamically created custom plugin?
B
5
S
1
Posts: 28
Reputation: 431

Post » Mon May 05, 2014 2:50 am

You might try a "behavior" instead of "plugin".
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Post » Mon May 05, 2014 7:29 am

How'd it look like with behaviors (logic-wise)?
B
5
S
1
Posts: 28
Reputation: 431

Post » Mon May 05, 2014 7:54 am

Behavior could get the sprite instance by "this.inst". Each behavior could control its host sprite directly and independent.
See the bullet behavior for example.
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Post » Mon May 05, 2014 8:12 am

Yeah, it'd save me having to pass the sprite to a plugin in an action. Anything else other than that?
B
5
S
1
Posts: 28
Reputation: 431

Post » Mon May 05, 2014 8:29 am

You could control each sprite instance individually, include the animation frame (and all actions of sprite).
Does it miss something?
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Post » Mon May 05, 2014 8:50 am

It's better ofcourse than doing it with a plugin, but as it is now it'll require me to do alot of repetitive work.

I'd like to have something that'll contain and control a FEW instances of sprite.
I'd like to have a few separate instances of that something, that have the exact same functionality.
B
5
S
1
Posts: 28
Reputation: 431

Post » Mon May 05, 2014 8:55 am

@royibernthal

The different between plugin or behavior in your case is that do you want control each sprite individually, i.e, do you have any private variables need to restore while control the sprite.

Other things might be the same, you could call all functions, assign all instance variables of sprite instance, after you got the instance reference.
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Post » Mon May 05, 2014 9:02 am

Yeah I am going to need extra variables and functionality for each individual sprite, which is why I'm going to use a behavior for that specific part like you suggested.

There's still the bigger picture though to think about.

Not sure I understood what you meant in your second sentence. Could you please rephrase / give an example?
B
5
S
1
Posts: 28
Reputation: 431

Post » Mon May 05, 2014 9:09 am

Assume you had got the sprite instance (named sprite_inst)

You might open "runtime.js" in html5\plugins\sprite folder, find the interface of "Action:Set animation" at line 1499.
Now you could call this action in your plugin/behavior by
Code: Select all
cr.plugins_.Sprite.prototype.acts.SetAnim.call(sprite_inst, animname, from);


"call" is a javascript feature.
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Next

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests