Inherit actions?

For developers using the Construct 2 Javascript SDK

Post » Fri Apr 26, 2013 3:50 am

I'm looking for a way to apply the same set actions to any Sprite object type.

More specifically, I have different types of Sprites to which I apply the same Physics actions (from the Physic behavior) to each object except with different angles. Now I know I can create a family but then I wouldn't be able to set different angles (would I?).

So I thought maybe I could create a function in the Event sheet and set a custom condition that picks the Sprite and then have access to the Actions available to the picked instance without duplicating them in my plugin. This way I can call this function in the Event sheet for each of the Sprite types to apply the actions.

Is it possible to inherit actions like that?

Thanks.
B
12
S
3
G
3
Posts: 36
Reputation: 3,048

Post » Fri Apr 26, 2013 4:25 am

@MakubeX

You could call sprite's (or other object) action function at other plugin/behavior.

Reference - call "text: set text" at it's behavior.
[code]cr.plugins_.Text.prototype.acts.SetText.apply(this.inst, [s]);[/code]rexrainbow2013-04-26 04:27:21
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Fri Apr 26, 2013 5:22 am

Thanks Rex, I'll try that.
B
12
S
3
G
3
Posts: 36
Reputation: 3,048

Post » Sat Apr 27, 2013 4:07 am

@rexrainbow

I tried calling the Physics behavior action ApplyImpulseAtAgnle from within one of the actions in my plugin but it throws and error when the function ApplyImpulseAtAgnle() tries to call the function getInstImgPointX().

Error says: 'this.getInstImgPointX is not a function'

So it looks like problem is 'this' is referencing my plugin. Is there a way around this?

Thanks!
MakubeX2013-04-27 04:34:18
B
12
S
3
G
3
Posts: 36
Reputation: 3,048

Post » Sat Apr 27, 2013 5:08 am

I have a gravity behavior which call set force at physical behavior.rexrainbow2013-04-27 05:09:41
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Sat Apr 27, 2013 5:36 am

@rexrainbow

Funny, I was already looking at that after finding it in an older post.

Edit: Ok, I see what you pointed out. I have to get an instance of the Physics behavior.

Thanks for the info, I'll report back with my results.


Edit 2: Everything worked perfectly. Thanks again!MakubeX2013-04-27 07:51:47
B
12
S
3
G
3
Posts: 36
Reputation: 3,048


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests