How I can create instance in plugin?

0 favourites
  • 4 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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:

    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
    );

    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 onlinedisk.ru/file/772010

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

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

    this.runtime.createInstance(obj, layer, x, y);

    That's how your plugin should create instances too.

  • 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:

    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();
    

    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"?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)