Posted: 9th Feb 2022 20:34
Hi there!

The only two lines of code I used:
+ Code Snippet
pecking=LoadGroupAnimation(LabRats_chickenarray,"Animations/__brown_chicken_peck_")
PlayGroupAnimationRandomOffset(pecking,15)

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:

+ Code Snippet
//‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣
//SINGLE SPRITE ANIMATION FUNCTIONS
//‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣
 
//Single Sprite Animation Import
function LoadAnimation(spriteID, imagename as string) //Load all images with the same imagename into the animation. Returns the animation ID when called.
 
//Play an animation as loop:
function PlayAnimation(AnimationID,FPS)//Refer to the animation via it's animation ID
 
//Play an animation once:
function PlayAnimationOnce(AnimationID,FPS)
 
//Play an animation starting with offset, as loop:
function PlayAnimationOffset(AnimationID,FPS,Offset)//Play the animation starting with a specific frame offset. Instead of frame 1 of the animation, you can choose any other frame
 
//Play an animation starting with a random offset:
function PlayAnimationRandomOffset(AnimationID,FPS)//Play the animation starting with a Random frame offset. You can use this to create randomness to your animations.
 
//Find out if a specific animation is playing:
function IsAnimationPlaying(AnimationID)//only works for animations loaded as single sprites. Not for group animations (you'll get wrong results if you call it on group animations).
 
//Find out which animation is playing or which animation the current sprite frame belongs to
//(returns -1 if the current frame belongs to no created animation):
function CurrentAnimation(spriteID)//works only for animations loaded as single sprites.
 
//Faster function to replace GetSpritePlaying:
function IsAnimating(SpriteID)
 
 
 
//‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣
//GROUP ANIMATION FUNCTIONS
//‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣
 
//Load the same animations for an entire group array of sprites:
function LoadGroupAnimation(GroupArrayID as integer[],imagename as string)//returns the Group Animation ID when called
 
//Play the Group animation for the entire group array as loop:
function PlayGroupAnimation(GroupArrayID,FPS)
 
//Play the Group animation for the entire group array as loop, but starting with an offset, not Frame 1:
function PlayGroupAnimationOffset(GroupArrayID,FPS,Offset)
 
//Play the Group animation for the entire group array as loop, but every single sprite starts with an individually random offset:
function PlayGroupAnimationRandomOffset(GroupArrayID,FPS)
 
//Play only one sprite in the Group Animation sprite group as loop:
function PlayGroupObject(spriteID,GroupAnimationID,FPS)//you give the spriteID directly of the sprite you want to animate, and the program animates only that sprite with the animation that was loaded for the entire sprite group.
 
//Play only one sprite in the Group Animation sprite group , only once:
function PlayGroupObjectOnce(spriteID,GroupAnimationID,FPS)
 
//Play only one sprite in the Group Animation sprite group , starting with an offset frame:
function PlayGroupObjectOffset(spriteID,GroupAnimationID,FPS,Offset)
 
//Play a defined part of your group sprites with the group animation:
function PlayGroupObjectList(GroupAnimationID,Animation_ID_start,Animation_ID_end,FPS)
//example: you used LoadGroupAnimation function on a group array of 20 sprites. Now if you want to animate sprites 10 to 15 of that group,
//you simply set Animation_ID_start to 10 and Animation_ID_end to 15.
 
//Play a defined part of your group sprites with the group animation, starting with a frame offset:
function PlayGroupObjectListOffset(GroupAnimationID,Animation_ID_start,Animation_ID_end,FPS,Offset)
 
//Play a defined part of your group sprites with the group animation, starting with an individually random frame offset for each sprite:
function PlayGroupObjectListRandomOffset(GroupAnimationID,Animation_ID_start,Animation_ID_end,FPS)
 
 
//‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣
//SPRITE SHEET FUNCTIONS:
//‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣
 
//load a sprite sheet animation into a single sprite:
function LoadAnimationSS(spriteID,ImagePathSS as string,iFrameWidth,iFrameHeight,iFrameCount)// returns the animation ID when called
 
//load a sprite sheet animation into a group array of sprites as a group animation
function LoadGroupAnimationSS(GroupArrayID as integer[],ImagePathSS as string,iFrameWidth,iFrameHeight,iFrameCount)// returns the group animation ID when called
 
 
//‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣
//DEFAULT ANIMATION LOAD FOLDER:
//‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣‣
//Set or reset a default animationfolder:
//the images will be loaded using that folder as a root folder inside the media folder:
function SetAnimationFolder(folderpath as string)
 
//Delete the default animation folder:
//images will be loaded from the media folder as the root folder:
function DeleteAnimationFolder()




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:
+ Code Snippet
color=LoadAnimation(LabRats_chickensprite,"Animations/chickencolor")
PlayAnimation(color,1)

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:
+ Code Snippet
disco=LoadGroupAnimation(LabRats_chickenarray,"Animations/chickencolor")
PlayGroupObjectListOffset(disco,6,10,1,3)

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:
+ Code Snippet
disco=LoadGroupAnimation(LabRats_chickenarray,"Animations/chickencolor")
PlayGroupObjectListRandomOffset(disco,1,5,1)

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:
+ Code Snippet
SetAnimationFolder("Animations")//SetAnimationFolder("Animations/") would also work

disco=LoadGroupAnimation(LabRats_chickenarray,"chickencolor")//using only "chickencolor" as reference, instead of "Animations/chickencolor"
PlayGroupObjectListRandomOffset(disco,1,5,1)

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:
+ Code Snippet
shooting=LoadGroupAnimationSS(LabRats_peoples,"list2.png",48,48,6)//declare the sprite group array, the image path, frame width and height, and the frame count
PlayGroupAnimationRandomOffset(shooting,5)

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:
+ Code Snippet
//COPYRIGHT BY WIZARD RANCH.
//INCLUDE THIS NOTICE WHEN USING THIS CODE.
//You may use this code freely for any commercial and non commercial products.
//However you are not allowed to distribute it under your own name or claim to be the author of it.

global testimage
testimage=1234567890123456789
global imageformat as string
//start with which numeration:
global first as string
//save all loaded images:
global MyLoadedImages as integer[]

function DidImportWork(imagename as string)
	ERmessage as string
	ERmessage=GetLastError()
	wordlength=Len(imagename)
	if Left(ERmessage,21)="Could not find image:" and Right(ERmessage,wordlength)=imagename
		exitfunction 0
	endif
	
endfunction 1

function LoadImageFrame(imagename as string)
	//reference call the testimage to make sure old errors from the last loop don't interfere:
	LoadImage(testimage,"..........")
	DeleteImage(testimage)
	LoadImage(testimage,imagename)
	
	itworked=DidImportWork(imagename)
	DeleteImage(testimage)
endfunction itworked

function LoadAnyFormat(imagename as string)
	if LoadImageFrame(imagename+".png")
		imageformat=".png"
		exitfunction 1
	elseif LoadImageFrame(imagename+".jpg")
		imageformat=".jpg"
		exitfunction 1
	elseif LoadImageFrame(imagename+".bmp")
		imageformat=".bmp"
		exitfunction 1
	endif
endfunction 0

function TestRunImage(imagename as string)
	//first try to start with zero:
	first="0"
	if LoadAnyFormat(imagename+first)
		exitfunction 1
	else
		first="00"
		if LoadAnyFormat(imagename+first)
			exitfunction 1
		else
			first="000"
			if LoadAnyFormat(imagename+first)
				exitfunction 1
			else
				first="0000"
				if LoadAnyFormat(imagename+first)
					exitfunction 1
				else
					first="1"
					if LoadAnyFormat(imagename+first)
						exitfunction 1
					else
						first="01"
						if LoadAnyFormat(imagename+first)
							exitfunction 1
						else
							first="001"
							if LoadAnyFormat(imagename+first)
								exitfunction 1
							else
								first="0001"
								if LoadAnyFormat(imagename+first)
									exitfunction 1
								else
								endif
							endif
						endif
					endif
				endif
			endif
		endif
	endif
endfunction 0

//check if image has already been loaded before:
function InMyLoadedImages(imagepath as string)
	for x=0 to MyLoadedImages.length
		if GetImageFilename(MyLoadedImages[x])=imagepath
			exitfunction MyLoadedImages[x]
		endif
	next
endfunction 0


Type Animation
	data as integer[]
EndType

global AnimationList as Animation[]

function LoadAnimation(spriteID, imagename as string)
	SetErrorMode(0)
	//add the default folder if given:
	if not AnimationFolder=""
		imagename=AnimationFolder+imagename
	endif
	if TestRunImage(imagename)
		
		//insert sprite ID to the saved animation data:
		NewAnimation as Animation
		NewAnimation.data.insert(spriteID)
		
		currentfirst as string
		currentfirst=first
		
		//insert the first sprite of the animation into the saved animation data:
		NewAnimation.data.insert(GetSpriteFrameCount(spriteID)+1)
		while LoadImageFrame(imagename+currentfirst+imageformat)
			
			//Load the image to the animation:
			ImageID=InMyLoadedImages(imagename+currentfirst+imageformat)
			if ImageID
				AddSpriteAnimationFrame(spriteID,ImageID)
			else
				newimage=LoadImage(imagename+currentfirst+imageformat)
				MyLoadedImages.insert(newimage)
				AddSpriteAnimationFrame(spriteID,newimage)
			endif
			
			//move to the next image:
			if val(currentfirst)<9
				newvalue=val(Right(currentfirst,1))
				newvalue=newvalue+1
				newfirst as string
				newfirst=Left(currentfirst,Len(currentfirst)-1)+str(newvalue)
				currentfirst=newfirst
			elseif val(currentfirst)=9
				if len(currentfirst)<3
					currentfirst="10"
				else
					newfirst=Left(currentfirst,Len(currentfirst)-2)+"10"
					currentfirst=newfirst
				endif
			elseif val(currentfirst)>9 and val(currentfirst)<99
				newvalue=val(Right(currentfirst,2))
				newvalue=newvalue+1
				newfirst=Left(currentfirst,Len(currentfirst)-2)+str(newvalue)
				currentfirst=newfirst
			elseif val(currentfirst)=99
				if len(currentfirst)<4
					currentfirst="100"
				else
					newfirst=Left(currentfirst,Len(currentfirst)-3)+"100"
					currentfirst=newfirst
				endif
			elseif val(currentfirst)>99  and val(currentfirst)<999
				newvalue=val(Right(currentfirst,3))
				newvalue=newvalue+1
				newfirst=Left(currentfirst,Len(currentfirst)-3)+str(newvalue)
				currentfirst=newfirst
			elseif val(currentfirst)=999
				if len(currentfirst)<5
					currentfirst="1000"
				else
					newfirst=Left(currentfirst,Len(currentfirst)-4)+"1000"
					currentfirst=newfirst
				endif
			elseif val(currentfirst)>999  and val(currentfirst)<9999
				newvalue=val(Right(currentfirst,4))
				newvalue=newvalue+1
				newfirst=Left(currentfirst,Len(currentfirst)-4)+str(newvalue)
				currentfirst=newfirst	
			endif
			
		endwhile
		//insert the last sprite of the animation into the saved animation data:
		NewAnimation.data.insert(GetSpriteFrameCount(spriteID))
		
		AnimationList.insert(NewAnimation)
		AnimationID=AnimationList.length
		SetErrorMode(2)
		exitfunction AnimationID
		
	endif
	message("Error in 'LoadAnimation' function: Couldn't find the image you were looking for.")
	message("Returning value -1 as AnimationID")
endfunction -1


//Play an animation as loop:
function PlayAnimation(AnimationID,FPS)
	spriteID=AnimationList[AnimationID].data[0]
	firstSprite=AnimationList[AnimationID].data[1]
	lastSprite=AnimationList[AnimationID].data[2]
	PlaySprite(spriteID,FPS,1,firstSprite,lastSprite)
endfunction

//Play an animation once:
function PlayAnimationOnce(AnimationID,FPS)
	spriteID=AnimationList[AnimationID].data[0]
	firstSprite=AnimationList[AnimationID].data[1]
	lastSprite=AnimationList[AnimationID].data[2]
	PlaySprite(spriteID,FPS,0,firstSprite,lastSprite)
endfunction

//Play an animation starting with offset:
function PlayAnimationOffset(AnimationID,FPS,Offset)
	spriteID=AnimationList[AnimationID].data[0]
	firstSprite=AnimationList[AnimationID].data[1]
	lastSprite=AnimationList[AnimationID].data[2]
	PlaySprite(spriteID,FPS,1,firstSprite,lastSprite)
	StopSprite(spriteID)
	if Offset>=0 and Offset<=lastSprite-firstSprite
		SetSpriteFrame(spriteID,firstSprite+Offset)
	else
		message("Error in 'PlayAnimationOffset' function: Please make sure the offset is between 0 and the maximum Frame of the animation (max. Frame: "+str(lastSprite-firstSprite)+").")
		message("The animation will start from Frame 0.")
	endif
	ResumeSprite(spriteID)
endfunction

//Play an animation starting with a random offset:
function PlayAnimationRandomOffset(AnimationID,FPS)
	firstSprite=AnimationList[AnimationID].data[1]
	lastSprite=AnimationList[AnimationID].data[2]
	OffsetMax=lastSprite-firstSprite//)/2)+1
	Offset=Random(0,OffsetMax)
	PlayAnimationOffset(AnimationID,FPS,Offset)
endfunction

//Find out if a specific animation is playing:
function IsAnimationPlaying(AnimationID)
	spriteID=AnimationList[AnimationID].data[0]
	firstSprite=AnimationList[AnimationID].data[1]
	lastSprite=AnimationList[AnimationID].data[2]
	if GetSpritePlaying(spriteID) and GetSpriteCurrentFrame(spriteID)>=firstSprite and GetSpriteCurrentFrame(spriteID)<=lastSprite
		exitfunction 1
	endif
endfunction 0

//Find out which animation is playing or which animation the current sprite frame belongs to
//(returns -1 if the current frame belongs to no created animation):
function CurrentAnimation(spriteID)
	currentSprite=GetSpriteCurrentFrame(spriteID)
	
	for AnimationID=0 to AnimationList.length
		AnimationSpriteID=AnimationList[AnimationID].data[0]
		firstSprite=AnimationList[AnimationID].data[1]
		lastSprite=AnimationList[AnimationID].data[2]
		if SpriteID=AnimationSpriteID and currentSprite>=firstsprite and currentSprite<=lastSprite
			exitfunction AnimationID
		endif
	next
endfunction -1

//Faster function for GetSpritePlaying:
function IsAnimating(SpriteID)
	result=GetSpritePlaying(SpriteID)
endfunction result



//GROUP ANIMATION FUNCTIONS

Type GroupAnimation
	animationlist as integer[]
EndType

global GroupAnimationList as GroupAnimation[]

function LoadGroupAnimation(GroupArrayID as integer[],imagename as string)
	NewGroupAnimation as GroupAnimation
	for x=0 to GroupArrayID.length
		newanimation=LoadAnimation(GroupArrayID[x],imagename)
		NewGroupAnimation.animationlist.insert(newanimation)
	next
	GroupAnimationList.insert(NewGroupAnimation)
	GroupID=GroupAnimationList.length
endfunction GroupID

function PlayGroupAnimation(GroupArrayID,FPS)
	for x=0 to GroupAnimationList[GroupArrayID].animationlist.length
		animationID=GroupAnimationList[GroupArrayID].animationlist[x]
		PlayAnimation(animationID,FPS)
	next
endfunction

function PlayGroupAnimationOffset(GroupArrayID,FPS,Offset)
	for x=0 to GroupAnimationList[GroupArrayID].animationlist.length
		animationID=GroupAnimationList[GroupArrayID].animationlist[x]
		PlayAnimationOffset(animationID,FPS,Offset)
	next
endfunction

function PlayGroupAnimationRandomOffset(GroupArrayID,FPS)
	for x=0 to GroupAnimationList[GroupArrayID].animationlist.length
		animationID=GroupAnimationList[GroupArrayID].animationlist[x]
		PlayAnimationRandomOffset(animationID,FPS)
	next
endfunction


function PlayGroupObject(spriteID,GroupAnimationID,FPS)
	for x=0 to GroupAnimationList[GroupAnimationID].animationlist.length
		AnimationID=GroupAnimationList[GroupAnimationID].animationlist[x]
		if AnimationList[AnimationID].data[0]=spriteID
			PlayAnimation(AnimationID,FPS)
		endif
	next
endfunction

function PlayGroupObjectOnce(spriteID,GroupAnimationID,FPS)
	for x=0 to GroupAnimationList[GroupAnimationID].animationlist.length
		AnimationID=GroupAnimationList[GroupAnimationID].animationlist[x]
		if AnimationList[AnimationID].data[0]=spriteID
			PlayAnimationOnce(AnimationID,FPS)
		endif
	next
endfunction

function PlayGroupObjectOffset(spriteID,GroupAnimationID,FPS,Offset)
	for x=0 to GroupAnimationList[GroupAnimationID].animationlist.length
		AnimationID=GroupAnimationList[GroupAnimationID].animationlist[x]
		if AnimationList[AnimationID].data[0]=spriteID
			PlayAnimationOffset(AnimationID,FPS,Offset)
		endif
	next
endfunction

function PlayGroupObjectList(GroupAnimationID,Animation_ID_start,Animation_ID_end,FPS)
	MaxItem=GroupAnimationList[GroupAnimationID].animationlist.length
	if Animation_ID_start-1>=0 and Animation_ID_start-1<= MaxItem
		if Animation_ID_end-1>=0 and Animation_ID_end-1<= MaxItem
			for x=Animation_ID_start-1 to Animation_ID_end-1
				animationID=GroupAnimationList[GroupAnimationID].animationlist[x]
				PlayAnimation(animationID,FPS)
			next
		else
			message("Error in 'PlayGroupObjectList' function: Please make sure the items ID are between 0 and the maximum Item ID (max. item ID: "+str(MaxItem+1)+").")
			message("No sprites will be animated.")
		endif
	else
		message("Error in 'PlayGroupObjectList' function: Please make sure the items ID are between 0 and the maximum Item ID (max. item ID: "+str(MaxItem+1)+").")
		message("No sprites will be animated.")
	endif
endfunction

function PlayGroupObjectListOffset(GroupAnimationID,Animation_ID_start,Animation_ID_end,FPS,Offset)
	MaxItem=GroupAnimationList[GroupAnimationID].animationlist.length
	if Animation_ID_start-1>=0 and Animation_ID_start-1<= MaxItem
		if Animation_ID_end-1>=0 and Animation_ID_end-1<= MaxItem
			for x=Animation_ID_start-1 to Animation_ID_end-1
				animationID=GroupAnimationList[GroupAnimationID].animationlist[x]
				PlayAnimationOffset(animationID,FPS,Offset)
			next
		else
			message("Error in 'PlayGroupObjectList' function: Please make sure the items ID are between 0 and the maximum Item ID (max. item ID: "+str(MaxItem+1)+").")
			message("No sprites will be animated.")
		endif
	else
		message("Error in 'PlayGroupObjectList' function: Please make sure the items ID are between 0 and the maximum Item ID (max. item ID: "+str(MaxItem+1)+").")
		message("No sprites will be animated.")
	endif
endfunction

function PlayGroupObjectListRandomOffset(GroupAnimationID,Animation_ID_start,Animation_ID_end,FPS)
	MaxItem=GroupAnimationList[GroupAnimationID].animationlist.length
	if Animation_ID_start-1>=0 and Animation_ID_start-1<= MaxItem
		if Animation_ID_end-1>=0 and Animation_ID_end-1<= MaxItem
			for x=Animation_ID_start-1 to Animation_ID_end-1
				animationID=GroupAnimationList[GroupAnimationID].animationlist[x]
				PlayAnimationRandomOffset(animationID,FPS)
			next
		else
			message("Error in 'PlayGroupObjectList' function: Please make sure the items ID are between 0 and the maximum Item ID (max. item ID: "+str(MaxItem+1)+").")
			message("No sprites will be animated.")
		endif
	else
		message("Error in 'PlayGroupObjectList' function: Please make sure the items ID are between 0 and the maximum Item ID (max. item ID: "+str(MaxItem+1)+").")
		message("No sprites will be animated.")
	endif
endfunction


//Spritesheet Functions:

function LoadAnimationSS(spriteID,ImagePathSS as string,iFrameWidth,iFrameHeight,iFrameCount)
	
	NewAnimation as Animation
	NewAnimation.data.insert(spriteID)
	firstFrame=GetSpriteFrameCount(spriteID)+1
	NewAnimation.data.insert(firstFrame)
	//check if the image is already loaded:
	ImageID=InMyLoadedImages(ImagePathSS)
	if ImageID
		SpriteSheetImage=ImageID
	else
		SpriteSheetImage=LoadImage(ImagePathSS)
		MyLoadedImages.insert(SpriteSheetImage)
	endif
	SetSpriteImage(spriteID,SpriteSheetImage)
	SetSpriteAnimation(spriteID,iFrameWidth,iFrameHeight,iFrameCount)
	lastFrame=GetSpriteFrameCount(spriteID)
	NewAnimation.data.insert(lastFrame)
	AnimationList.insert(NewAnimation)
	AnimationID=AnimationList.length
	
endfunction AnimationID

function LoadGroupAnimationSS(GroupArrayID as integer[],ImagePathSS as string,iFrameWidth,iFrameHeight,iFrameCount)
	NewGroupAnimation as GroupAnimation
	for x=0 to GroupArrayID.length
		newanimation=LoadAnimationSS(GroupArrayID[x],ImagePathSS,iFrameWidth,iFrameHeight,iFrameCount)
		NewGroupAnimation.animationlist.insert(newanimation)
	next
	GroupAnimationList.insert(NewGroupAnimation)
	GroupID=GroupAnimationList.length
endfunction GroupID

global AnimationFolder as string

//Set or reset a default animationfolder:
function SetAnimationFolder(folderpath as string)
	if Right(folderpath,1)="/" or Right(folderpath,1)="\"
		wordlength=Len(folderpath)
		folderpath=Left(folderpath,wordlength-1)
		folderpath=folderpath+"/"
	else
		folderpath=folderpath+"/"
	endif
	AnimationFolder=folderpath
endfunction

//Delete the default animation folder:
function DeleteAnimationFolder()
	AnimationFolder=""
endfunction