Animation.js (system script)
From Spheriki
Animation.js is an easy-to-use system script by fenix which allows having a sequence of images (for example image files) played as an animation one after another.
Contents |
Usage
RequireSystemScript("animation.js");
Variables and functions of animation.js
- Object constructor Animation()
- Each object created with this constructor will represent a sequence of images.
- Methods:
- addImage(image, timing) - adds an image to the sequence. The 'image' argument may either be a string with the name of an image file situated in the
imagesfolder of your project or an image object. 'timing' defines the number of milliseconds the image is shown. - blit(x, y) - draws the animation at the given screen position.
- reset() - restarts the animation.
- addImage(image, timing) - adds an image to the sequence. The 'image' argument may either be a string with the name of an image file situated in the
Examples
Let's say we have the three frames of an animated logo stored as logo1.png, logo2.png and logo3.png. This script will show the animation until a key is pressed:
RequireSystemScript("animation.js") var Logo = new Animation(); Logo.addImage("logo1.png", 300); Logo.addImage("logo2.png", 300); Logo.addImage("logo3.png", 300); while (!AreKeysLeft()) { Logo.blit(0, 0); FlipScreen(); }
Alternately, if the logo has already been loaded before, like...
var Logo1 = LoadImage("logo1.png"); var Logo2 = LoadImage("logo2.png"); var Logo3 = LoadImage("logo3.png");
...then you can - in the above example - call the addImage method like this:
Logo.addImage(Logo1, 300); Logo.addImage(Logo2, 300); Logo.addImage(Logo3, 300);
It'll do the same as before, but can save you loading time in some cases.
Notes
- The animation goes on forever. Use its
reset()method to make sure it starts with the first image in a given situation. - You'll have to use FlipScreen() after blitting. Otherwise you'll see nothing.