Jump to content

AnimatedSprite . onLoop function not working


MonseuirComede
 Share

Recommended Posts

Quote

var anim_array = [];
        this.animations[animation_name].forEach(function(img_path) {
          anim_array.push(PIXI.Texture.fromImage(animation_name + "/" + img_path));
});

var new_head = new PIXI.extras.AnimatedSprite(anim_array);
new_head.setTransform(old_head.x + 50, old_head.y + 50);


new_head.onLoop = function() {

          console.log("LOOPING");
          new_head.stop();
};


new_head.loop = true;
new_head.animationSpeed = .1;


new_head.play();

app.stage.addChild(new_head);

 

Code above (within a function called animate_head). Won't log "LOOPING" or stop, but the animation displays on canvas and loops infinitely. Have been looking through forums and have no clue.

The stop() call is just so I know the onLoop is working. With or without that line, still doesn't log.

Link to comment
Share on other sites

Have been looking through forums and have no clue.

Welcome to open-source. AnimatedSprite is very easy class that is supposed to be overriden by dev, usually its functions are not enough.

Place breakpoint there and debug whatever is wrong: https://github.com/pixijs/pixi.js/blob/dev/packages/sprite-animated/src/AnimatedSprite.js#L273

What version of pixijs do you use?

 

Link to comment
Share on other sites

Thank you very much for the reply!

I went to make the breakpoint and it turns out I was using a script tag in the client towards an old version of pixi on Cloudflare before the addition of onLoop. I am updating the script tag to a static route towards the correct file in node_modules (per https://stackoverflow.com/questions/27464168/how-to-include-scripts-located-inside-the-node-modules-folder).

I am indeed rather new to open source and had some skittishness about digging into libraries. I'll abolish that effect - for the future, when overriding a Pixi class, do you modify the js file directly or some other method?

Thank you again.

Link to comment
Share on other sites

I am indeed rather new to open source and had some skittishness about digging into libraries. I'll abolish that effect - for the future, when overriding a Pixi class, do you modify the js file directly or some other method?

PixiJS is focused on source-code , we have very good selection process for PR's and dont allow strange things that most people cant understand into it.

you can extend class (override), you can patch it like "PIXI.AnimatedSprite.prototype.xxx = function() ... " or you can build your own pixi fork. I know big project with modified pixijs file, it happens.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...