Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Ok, I've been writing C# for a while, but I'm new to ActionScript, so this is a question about best practices.

We're developing a simple match game, where the user selects tiles and tries to match various numbers - sort of like memory - and when the match is made we want a series of animations to take place, and when they're done, remove the tile and add a new one.

So basically it's:

  1. User clicks the MC
  2. Animation 1 on the MC starts
  3. Animation 1 ends
  4. Remove the MC from the stage
  5. Add a new MC
  6. Start the animation on the new MC

The problem I run into is that I don't want to make the same timeline motion tween on each and every tile, when the animation is all the same. It's just the picture in the tile that's different.

The other method I've come up with is to just apply the tweens in code on the main stage. Then I attach an event handler for MOTION_FINISH, and in that handler I trigger the next animation and listen for that to finish etc. This works too, but not only do I have to do all the tweening in code, I have a seperate event handler for each stage of the animation.

So is there a more structured way of chaining these animations together?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Definitely have a look at the greensock Tweening library. Especially TweenLite and TimelineLite. It's a really great tweening library and will definitely make tasks like the one you're facing a lot easier.

share|improve this answer
    
These were all great answers, but I settled on TweenLite. It's easier for me since I prefer code to timeline work, and it lets me tween multiple properties at once and fire them on a delay. That library rocks! –  LoveMeSomeCode Mar 15 '11 at 14:12

So there seem like two good ways to solve this. The first is to take Bummzack's advice and use TweenLite to programmatically advance your movie clip. When the tween finishes you can then remove the clip and carry on. The second approach I've used is to add an event to the final frame in your movie clip. Usually I will fire an EVENT_COMPLETE event in the final frame. The game would then add the movie clip, start playing it, and listen for the complete event.

share|improve this answer
    
That's actually what I tried first. It did work, but the issue I had was this: I have over 2 dozen bitmaps, and I want each tile to use a different one. Otherwise I want them all to react same; same timeline animation, same custom event at the end of each animation etc. Is there a way to where I don't have to add that motion tween and event code to 20 some movie clips if it's all the same except the graphic? –  LoveMeSomeCode Feb 11 '11 at 1:57
    
You should create a separate class for your MovieClip and write the behavior there. You can then assign the same class to all of your graphics. So the graphic will change, but all will have the same behavior (since they are the same class). –  bummzack Feb 11 '11 at 8:08
    
The graphic can be changed at runtime using a variable. You do not need to create 20 movie clips. Use only one movie clip. As I wrote earlier you can create multiple animations in the same clip too. The animation you run (i.e. start frame to end frame) and the graphic you display can be set by variables. –  kosmoknot Mar 10 '11 at 16:40
    
Thanks for the info. That method actually did work, we had 1 blank MC, animated it in the timeline, and added the graphics in code. But we still settled on TweenLite just for it's simplicity. I can write code, but i'm not good and doing timeline tweens graphically. –  LoveMeSomeCode Mar 15 '11 at 14:13

Timeline animation is fun and quick to create. As you mentioned only the image(s) in the tile changes. I would create a tile (with animation) on a the timeline and load the image(s) into it. Use frame labels and base your logic on the current frame label.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.