Change sprite animation speed with a Behavior

0 favourites
  • 2 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • Hi,

    I'm making a behavior that's supposed to be attached to Sprite objects.

    I want that behavior to set the animation speed of the sprite once that sprite is created.

    And this is what I do in the behavior:

    	behinstProto.onCreate = function()
    	{
    		cr.plugins_.Sprite.prototype.acts.SetAnimSpeed.call(this.inst,0);
    	};
    [/code:3d8r6s5s]
    
    Unfortunately that does nothing, because apparently the sprite object's instantiation/initialization comes after behinstProto.onCreate() and override my setting.
    One solution is to put it in behinstProto.tick() but I don't want to add initialization stuff in the tick function.
    
    One other hackish solution:
    [code:3d8r6s5s]
    	behinstProto.onCreate = function()
    	{
    		var self = this.inst;
    		setTimeout(function(){
    			cr.plugins_.Sprite.prototype.acts.SetAnimSpeed.call(self,0);
    		},0);
    	};
    [/code:3d8r6s5s]
    Do you have a better solution ?
    Thanks.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Using a boolean to indicate the first tick and then doing it in the tick function is a cleaner solution to me.

    behinstProto.onCreate = function()
    {
       this.firstTick = true;
    };
    
    behinstProto.tick = function()
    {
       if (this.firstTick)
       {
          this.firstTick = false;
          cr.plugins_.Sprite.prototype.acts.SetAnimSpeed.call(this.inst,0);
       }
    };[/code:3iyvjmxy]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)