How I can create instance in plugin?

Get help using Construct 2

Post » Thu Nov 17, 2011 11:34 pm

Hello, I try create a behavior "Weapon".
Now I can't create a Instance of bullet in my plugin.
My actions:
1. Create a bullet on project.
2. Create a "tank" with weapon.
3. Add my behavior "Weapon" to the "tank".
4. On the "space" key down I make a shoot from weapon by bullet from step 1.
But for it I must create a new bullet from my behavior script. I saw in Events sheet, that my "tank" as Sprite can use Spawn function for create new Instance Bullet. From script it looks terrible in my performance:

[code]this.type.objtype.plugin.acts.Spawn.call(
    this.type.objtype.instances[0],
    this.runtime.types_by_index[2],
    this.runtime.getLayerByNumber(this.bullet_layer),
    1
);[/code]

And of course, it does not work. Causes an error somewhere in eventg.js, as shown by firebug:
evinfo.current_event is null
return evinfo.current_event.actions[evinfo.actindex];    eveng.js (line 1576)

I think it should be way easier and more beautiful, but I have not found anywhere else.

Help me, please.

Raw current variant of plugin you can download from http://www.onlinedisk.ru/file/772010/JohnJ2011-11-17 23:49:53
B
4
S
1
G
1
Posts: 36
Reputation: 949

Post » Fri Nov 18, 2011 7:04 am

Not sure exactly what you want to do, but in general the plugs dont create objects, they only act as conditions, or triggers to make that process easier.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Fri Nov 18, 2011 3:32 pm

Don't try to call Sprite's Spawn action! That won't work. Look at what Sprite's spawn method actually does - it calls

[code]this.runtime.createInstance(obj, layer, x, y);[/code]

That's how your plugin should create instances too.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,528

Post » Fri Nov 18, 2011 3:49 pm

Thank's! I do it! :) Now I have a weapon on any created object by behavior... But now I need to finish the behavior. Thank you for help!
in case you can simplify things, here's what I got:
[code]var plugin = this.type.objtype.instances[0];
var image_point = {
    x: plugin.getImagePoint(this.bullet_point, true),
    y: plugin.getImagePoint(this.bullet_point, false)
}
var new_bullet_inst = this.runtime.createInstance(
    this.runtime.types_by_index[2],
    this.runtime.getLayerByNumber(this.bullet_layer),
    image_point.x,
    image_point.y
);
new_bullet_inst.angle = this.angle;
new_bullet_inst.set_bbox_changed();
[/code]

I can't find a function for replace this.runtime.types_by_index[2] to this.runtime.getTypeByName('Bullet'). If I wanted to create this function, where should I do this? change the program files do not want to, as the upgrade version will be updated ...
And what about properties types. I need a ept_keyb and ept_instance types :) Now I use float and text instead of it, but it is not usability...
And... How can I require that my behavior can only be used for sprites or other plugins that have method "getImagePoint" at "edittime"?JohnJ2011-11-18 15:56:01
B
4
S
1
G
1
Posts: 36
Reputation: 949


Return to How do I....?

Who is online

Users browsing this forum: michaelverdi and 25 guests