hyperandroid / CAAT

Canvas Advanced Animation Toolkit
hyperandroid.github.com/CAAT
MIT License
727 stars 117 forks source link

Stop sprite image animation #165

Open vitorcominato opened 10 years ago

vitorcominato commented 10 years ago

Hi, I have a CAAT.Foundation.SpriteImage() animation and i would like to pause the animation and position the image paused in a certain frame, i didn't foud nothing like this. It is possible to do that? Here is my code. Thak you very much.

screenManager.sAnimaIntro = new CAAT.Foundation .SpriteImage() .initialize(screenManager.gameScreen.getImage(screenManager.ANIMA_INTRO), 9, 9) .addAnimation( screenManager.ANIMA_INTRO, [00,00,00,00,00,00,00,01,02,03, 03,03,03,03,03,03,04,05,00,00, 06,07,08,09,09,09,09,09,09,09, 09,09,09,09,09,09,09,09,09,08, 10,11,00,00,00,00,00,12,13,14, 14,14,14,14,14,14,14,14,14,14, 15,16,00,00,00,00,00,00,00,00, 00,00,00,17,18,19,20,21,22,23, 24,25,26,27,28,28,29,00,00,30, 31,32,33,34,35,35,35,35,35,35, 35,35,36,37,38,39,40,40,40,40, 40,40,41,42,43,44,45,46,47,48, 49,49,49,49,49,49,49,49,49,49, 49,50,51,52,53,54,55,00,00,56, 57,58,59,60,61,62,63,64,65,66, 67,68,69,70,71,72,72,72,72,72, 72,72,72,72,72,72,72,72,72,72, 72,72,72,72,72,72,72,72,72,72, 73,74,75,76,77,78,79,61,58,57, 80,56,56,00,00,00,00,00,00,00], 35);

hyperandroid commented 10 years ago

You could define another animation with only the expected frame and then call spriteImage.playAnimation("one_frame_animation") anytime. in fact you could define as much animations as needed.

2014-02-27 8:24 GMT-08:00 Vitor Cominato notifications@github.com:

Hi, I have a CAAT.Foundation.SpriteImage() animation and i would like to pause the animation and position the image paused in a certain frame, i didn't foud nothing like this. It is possible to do that? Here is my code. Thak you very much.

screenManager.sAnimaIntro = new CAAT.Foundation .SpriteImage() .initialize(screenManager.gameScreen.getImage(screenManager.ANIMA_INTRO), 9, 9) .addAnimation( screenManager.ANIMA_INTRO, [00,00,00,00,00,00,00,01,02,03, 03,03,03,03,03,03,04,05,00,00, 06,07,08,09,09,09,09,09,09,09, 09,09,09,09,09,09,09,09,09,08, 10,11,00,00,00,00,00,12,13,14, 14,14,14,14,14,14,14,14,14,14, 15,16,00,00,00,00,00,00,00,00, 00,00,00,17,18,19,20,21,22,23, 24,25,26,27,28,28,29,00,00,30, 31,32,33,34,35,35,35,35,35,35, 35,35,36,37,38,39,40,40,40,40, 40,40,41,42,43,44,45,46,47,48, 49,49,49,49,49,49,49,49,49,49, 49,50,51,52,53,54,55,00,00,56, 57,58,59,60,61,62,63,64,65,66, 67,68,69,70,71,72,72,72,72,72, 72,72,72,72,72,72,72,72,72,72, 72,72,72,72,72,72,72,72,72,72, 73,74,75,76,77,78,79,61,58,57, 80,56,56,00,00,00,00,00,00,00], 35);

Reply to this email directly or view it on GitHubhttps://github.com/hyperandroid/CAAT/issues/165 .

vitorcominato commented 10 years ago

I will detail better for you,

I have a 8 animations in one actor. I randomize which animation will go on the actor. After the animation is finished, i run a reset animation that look like this: screenManager.sAnimaBottom.addAnimation( screenManager.RESET_ANIMATION, [00,00,00,00,00], 100 ); Then i randomize the animation again. But after some time running this animations, the Frame per seconds rate run very low and i get this error on chrome console:

Uncaught TypeError: Cannot read property 'x' of undefined caat.js:17012 paintN caat.js:17012 paint caat.js:18756 paintActor caat.js:19778 paintActor caat.js:20434 paintActor caat.js:20434 render caat.js:22546 renderFrame caat.js:23362 CAAT.renderFrameRAF caat.js:15203

Thakns again.

hyperandroid commented 10 years ago

could you share the code ? that's unexpected behavior. On Feb 27, 2014 9:14 AM, "Vitor Cominato" notifications@github.com wrote:

I will detail better for you,

I have a 8 animations in one actor. I randomize which animation will go on the actor. After the animation is finished, i run a reset animation that look like this: screenManager.sAnimaBottom.addAnimation( screenManager.RESET_ANIMATION, [00,00,00,00,00], 100 ); Then i randomize de animation again. But after some time running this animations, the Frame per seconds rate run very low and i get this error on chrome console:

Uncaught TypeError: Cannot read property 'x' of undefined caat.js:17012 paintN caat.js:17012 paint caat.js:18756 paintActor caat.js:19778 paintActor caat.js:20434 paintActor caat.js:20434 render caat.js:22546 renderFrame caat.js:23362 CAAT.renderFrameRAF caat.js:15203

Thakns again.

Reply to this email directly or view it on GitHubhttps://github.com/hyperandroid/CAAT/issues/165#issuecomment-36265885 .

vitorcominato commented 10 years ago

I fixed the FPS problem, but the error is still ocurring here is the code:

var si = new CAAT.Foundation .SpriteImage() .initialize(director.getImage("img"), 6, 7) // size image 3080x2820px 365kb .addAnimation( "anima", [00,01,02,03,04,05,06,07,08,09, 10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24,25,26,27,28,29, 30,31,19,20,21,22,33,34,35,36, 37,38], 35, function(e) { e.ownerActor.playAnimation("reset"); } ) .addAnimation( "reset", [38, 38, 38, 38, 38], 100 );

var elem = new CAAT.Foundation .Actor() .enableEvents(false) .setVisible(true) .setLocation( 50, 60 ) .setBackgroundImage(si);

scene.addChild(elem);

window.setInterval(function() { elem.playAnimation("anima"); }, 10000); elem.playAnimation("anima");

and the error:

Uncaught TypeError: Cannot read property 'x' of undefined caat.js:17012 paintN caat.js:17012 paint caat.js:18756 paintActor caat.js:19778 paintActor caat.js:20417 paintActor caat.js:20434 paintActor caat.js:20434 render caat.js:22546 renderFrame caat.js:23362 CAAT.renderFrameRAF caat.js:15203