Instances of a plugin that contains sprites

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

  • You might try a "behavior" instead of "plugin".

  • How'd it look like with behaviors (logic-wise)?

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

  • Yeah, it'd save me having to pass the sprite to a plugin in an action. Anything else other than that?

  • You could control each sprite instance individually, include the animation frame (and all actions of sprite).

    Does it miss something?

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

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

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

  • 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

    cr.plugins_.Sprite.prototype.acts.SetAnim.call(sprite_inst, animname, from);[/code:2l974fo2]
    
    "call"  is a javascript feature.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah looks like this could indeed help me.

    I get an error though: "undefined is not a function"

    Acts.prototype.SetSprite = function (sprite)
    	{
    		if (!sprite) return;
    		
    		cr.plugins_.Sprite.prototype.acts.SetAnimFrame.call(sprite, 2);
    	};[/code:1m9blwcg]
  • Do you put one sprite object in this project?

    You might check if (cr.plugins_.Sprite != null) first.

  • Yes I do put one sprite in this project, which is the sprite that I'm passing to this function.

    Acts.prototype.SetSprite = function (sprite)
    	{
    		if (!sprite) return;
    		
    		if (cr.plugins_.Sprite != null) cr.plugins_.Sprite.prototype.acts.SetAnimFrame.call(sprite, 2);
    		else alert("No Sprite");
    	};[/code:1j3q2uvw]
    
    Same error:
    
    [code:1j3q2uvw]Uncaught TypeError: undefined is not a function
    
    

    localhost/Sprite_plugin.js, line 1529 (col 9)[/code:1j3q2uvw]

  • I am not sure, I only could tell that I had made some plugins which access the ACE interface of plugin directly.

    For example,

    https://github.com/rexrainbow/C2_plugin ... runtime.js

    This plugin will access the condition, action, expression of webstorage object.

  • Any chance you'll try to help me figure out what's wrong with the Sprite's case?

    The function that is undefined is in the Sprite plugin and it's not the function I'm calling but a function call inside that function: this.doChangeAnimFrame();

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