ANIMATION DOLPHINS


Version francaise

The aim of this article is to show how to play a serie of bitmaps at the location of the mouse cursor when the user clicks. In order to do this, we are going to use the concepts of global list, behavior and message parsing.

 

Firstly, we need a serie of bitmaps representing a complete animation. To create a nice effect, the first and last bitmaps must be empty. Below, an animation of 31 bitmaps of a dolphin once imported in the cast.

I found this animation on the Internet as a .AVI file.

L'animation du dauphin, Microsoft Age of Empires II

In Macromedia Director, the white colour is used for transparency, so I imported the file into Microsoft Gif Animator, exported each bitmap as .GIF, then converted the blue background into a white one with Adobe Photoshop. Then, I imported every bitmaps in Macromedia Director and named them under the form of a letter followed by a number, the serie begins with a white bitmap (ie. d0, d1, ..., d30).

In the draw window, one must check that the registration point is the same for every bitmap, otherwise it will create a shift when it animates.

The Lingo scripting is relatively easy, there are only three scripts :

  1. A script on startmovie which initializes the global list free_sprites. This list contains the numbers of sprites which can be used to start an animation.
  2. A script on exitframe which manages the clicks and the sending of starting messages to the sprites of the free_sprites list .
  3. A script behavior which locally manages an animation, we will attach this script to every sprites.

Here is the detail of the three scripts :

 

on startmovie

global free_sprites

set free_sprites=[]

-- initialize an empty global list

end

on exitFrame

global free_sprites

if ((the mousedown=TRUE) and (count(free_sprites) <> 0)) then

-- IF the mousebutton is pressed

-- AND that the list is NOT empty THEN

sendsprite getat(free_sprites, 1), #start, point(the mouseh, the mousev)

-- Send a starting message to the first sprite of the list

-- with the mouse location as a parameter

end if

go the frame

-- loop on the frame

end

 
 

-- Behavior to manage a sprite animation

global free_sprites

property mysp, mymax, mycurrent, myletter, mystart

on beginsprite me

set mysp= the spritenum of me

-- Number of the sprite on the score

set mymax = 30

-- Maximum of bitmaps for the animation

set mycurrent = 0

-- Current bitmap to 0

set myletter = "d"

-- Letter or name of the serie

set mystart = 0

-- Animation trigger to 0

add(free_sprites, mysp)

-- Add its number to the free sprites list

end

 

on exitframe me

if mystart = 1 then

-- IF the animation is started THEN

set mycurrent = mycurrent + 1

-- Increment the number of the current bitmap

if mycurrent > mymax then

-- IF the current bitmap if greater than the maximum THEN

set mycurrent = 0

-- Put the current bitmap on the empty one

set mystart = 0

-- Stop the animation (trigger off)

add(free_sprites, mysp)

-- And add its sprite number to the free sprites list

end if

set the member of sprite mysp to member string(myletter&mycurrent)

-- Refresh the current bitmap

end if

end

 

on start me, newloc

set the loc of sprite mysp to newloc

-- Put the sprite at the location indicated by newloc

set mystart = 1

-- put the trigger to on and so start the animation on the next exitframe handler

deleteat(free_sprites, 1)

-- delete its number from the list

end

 

Finally, we must place the sprites on the stage, take care to put the first member of the serie (d0) as it will not be visible (empty bitmap). Then choose the transparent background and attach the behavior to the sprite. Copy-Paste the sprite several times, the number of sprites should be the number of bitmaps of the animation + 1 (ie. d0 .... d30 --> 32 sprites) in order to always have at least one free sprite in the free_sprites list.

 

On the left, the result as a Shockwave movie. Click on it to see the dolphins jumping out.

 

 

As a conclusion, it could be nice to transform this script in order to re-use it easily. For that, we should setup the variables mymax et myletter by putting them into a on getpropertydescriptionlist handler. It is then possible to manage several animations by using several global lists.

The compressed Director file (.ZIP 20kb) is here.

If you encounter any trouble during the implementation or if you have done something cool with this technique, I'm available here.