Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Amazing fully automated Animation Loading and Playback

Author
Message
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 9th Feb 2022 20:34 Edited at: 15th Feb 2022 17:53
Hi there!

The only two lines of code I used:

Result:
https://gyazo.com/cf5ab44a4505a77e4cd73f475235eeea

For my personal use I created some functions that fully automize and give an awful lot of additional features and flexibilty regarding animations.
I made them compatible with html (by implementing string functions instead of folder functions) and also compatible with spritesheets.
I used those functions to create all the animations for this game here with only a few lines of code!

If you use those functions you can very quickly load animations to sprites, to an entire group array of sprites, and animate those sprites starting with any frame you want, or with random offsets, to create more diversity to your animations!
All done with a few lines!
I share those functions so that anyone else who wants to significantly reduce their coding and developing time when writing scripts can use them.
If ever they happen to be useful to you, feel free to let me know.

First I will give a description of all of the functions.
Then some examples so you get a better feeling about what you can do with it.
After that I list a few important particularities.
And then at the bottom of the thread I pasted the function code itself that you can load into your project to use it if you like.



Descriptions of the functions:





Examples for clarity:
Sprite images used in the referenced folder for the first 4 examples (Screenshot of folder: "media/Animations"):

__________________________________________________________________________________________________________________________________
Example 1: LoadAnimation()
(Animating a single sprite at 1 FPS)

Code used:

Result: https://gyazo.com/8a4765f2d6e6ac2303076653cca6ecfd
__________________________________________________________________________________________________________________________________
Example 2: LoadGroupObjectListOffset()
(Selecting sprites 6 to 10 in the animation group, animating at 1 FPS, starting with a frame offset of 3 (so with frame 4 which is purple) )

Code used:

Result: https://gyazo.com/e027e2aeec156fa7699b17342f846a37
__________________________________________________________________________________________________________________________________
Example 3: LoadGroupObjectListRandomOffset()
(Selecting sprites 1 to 5 in the animation group, animating at 1 FPS, starting with random offsets from random frame on)

Code used:

Result: https://gyazo.com/86c2360ec0a0a71ccc4cec2f8547fc5d
__________________________________________________________________________________________________________________________________
Example 4: SetAnimationFolder()
(select default animation folder that is automatically added to the image path. Used in combination with example 3)

Code used:

Result: https://gyazo.com/15d2ac185b80b8ad39bd5d687fa95410
__________________________________________________________________________________________________________________________________
Example 5: Spritesheet example: LoadGroupAnimationSS() and PlayGroupAnimationRandomOffset():
(Loading a spritesheet to a group of sprites as animation and play them at 5 FPS from a random frame offset on)

Spritesheet used: 'list2.png' in the media folder:

Code used:

Result: https://gyazo.com/8cbc2a4efba8be702944be9282564086
__________________________________________________________________________________________________________________________________


Important particularities with the script:

1) When working with HTML, you need to pay attention to upper and lower case when giving your image path, otherwise it will crash.
2) To make it compatible with html I use a lot of string functions, which takes more time than using AGKs folder functions to load images. It's probably best to load your animations once in the beginning of the game for that reason.

3) How it works: You only need to give the main name of the image. The function automatically imports all images as an animation, and automatically recognizes the picture format ("png","jpg" or "bmp").
E.g.: In your folder "media/Animations/" you have the images "walk_main_001.png" to "walk_main_023.png". When loading you only reference "Animations/walk_main_" as the image name, and the function automatically imports all those images for you!
The images are recognized if they start either with 0 or 1. It recognizes up to four decimals for the numerization(e.g. "walk_main_0001.png" or "walk_main_01.png" both work)
4) The functions automatically checks if any image has already been loaded into cache and re-uses it, so you don't use up space by loading images multiple times
5) After each use of any animation loading function, the error mode gets set to error mode 2. If you wish to have a different error mode, you need to set it after you're finished loading all animations.


Full raw Code to copy and paste into your projects:

Login to post a reply

Server time is: 2024-11-17 22:21:52
Your offset time is: 2024-11-17 22:21:52