Jump to content

Switch beetween animations


HugoLuc
 Share

Recommended Posts

Hi everyone.I have been trying to make a prototype for a game and I'm wondering if there is any way to switch between sprite animation using MovieClip. 

 var frames = [];
            for (var i = 0; i < 4; i++) {
                
               var val = i < 10 ? '0' + i : i;

                // magically works since the spritesheet was loaded with the pixi loader
                frames.push(PIXI.Texture.fromFrame('ladyBug_Walk-0' + (i+1) + '.png'));
            }
            this.sprites.ladybugWalk = frames

//load frames with:(repeat for ladubugfly and ladybugWalk)
var frames = [];
var sprites = {};

for (var i = 0; i < 4; i++) {
   // magically works since the spritesheet was loaded with the pixi loader
   frames.push(PIXI.Texture.fromFrame('ladyBug_Walk-0' + (i+1) + '.png'));
}

sprites.ladybugWalk = frames;

//create movie clip with:

animation02 = new PIXI.extras.MovieClip(assets.sprites.ladybugFly);
animation01 = new PIXI.extras.MovieClip(assets.sprites.ladybugWalk);

//switch with:

aniamtion01.sprite = sprites.animation02;

If I do that I get this error:

TypeError: undefined is not an object (evaluating 'value.baseTexture.hasLoaded')

I've seen the example on the PIXI website in which it changes the sprite on click, but it was a single sprite and not a movie clip. Is there any way to switch the whole animation? If Not, what's the best way to do it? create a new MovieClip, kill the old one, and position it in the same place? 

Thank you!

Link to comment
Share on other sites

I haven't gotten to this yet, but have some thoughts.  One thought is to put 4 movieclips in a container and turn one visible and the last one not visible.  They would all take the position of the container that way so should stay aligned.  Haven't tried it though.  

Another is this code written by kittyKat:https://gist.github.com/kittykatattack/13a53d0dbc32ce2a0a17

You could use it as is, or just look at his code for getting a sequence and displaying it.

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