Kenyon Posted July 16, 2016 Share Posted July 16, 2016 Hey, I was wondering if anyone knows how to play a MovieClip only once? For a code example, my code is pretty similar to the example below: http://pixijs.github.io/examples/index.html?s=basics&f=spritesheet.js&title=SpriteSheet Animation Thanks! Quote Link to comment Share on other sites More sharing options...
themoonrat Posted July 16, 2016 Share Posted July 16, 2016 https://pixijs.github.io/docs/PIXI.extras.MovieClip.html var anim = new PIXI.extras.MovieClip( textures); anim.loop = false; ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Kenyon Posted July 16, 2016 Author Share Posted July 16, 2016 Hey @themoonrat, unfortunatly I have tried that but for some reason it doesn't play through once, it just loads the last frame. Here's what I have: window.onload = function() { var renderer = PIXI.autoDetectRenderer(1000, 620, { transparent: true }); document.body.appendChild(renderer.view); // create the root of the scene graph var stage = new PIXI.Container(); var background = new PIXI.Sprite.fromImage('city4.png'); background.setParent(stage); PIXI.loader.add('./data.json').load(onAssetsLoaded); var movie; function onAssetsLoaded() { var frames = []; for (var i = 0; i < 38; i++) { var val = i < 10 ? i : i; frames.push(PIXI.Texture.fromFrame('texture' + val + '.png')); } movie = new PIXI.extras.MovieClip(frames); movie.position.set(1000, 620); movie.anchor.set(1); movie.animationSpeed = -0.2; movie.play(); movie.loop = false; stage.addChild(movie); animate(movie); } function animate(movie) { renderer.render(stage); requestAnimationFrame(animate); } } Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 16, 2016 Share Posted July 16, 2016 Why is it -0.2? Quote Link to comment Share on other sites More sharing options...
Kenyon Posted July 16, 2016 Author Share Posted July 16, 2016 Hey @ivan.popelyshev I'm having my spriteSheet run in reverse. And I just realized that's why it's not playing. Anyway around this other than re-exporting my sprite in a different order? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 16, 2016 Share Posted July 16, 2016 why not just reverse the cycle? i think the problem is with "!loop && animationSpeed<0". Quote Link to comment Share on other sites More sharing options...
Kenyon Posted July 16, 2016 Author Share Posted July 16, 2016 Yep, reversing the loop fixed it. Thanks! for (var i = 38 - 1; i >= 0; i--) { var val = i < 10 ? i : i; frames.push(PIXI.Texture.fromFrame('texture' + val + '.png')); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.