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.

AppGameKit Studio Chat / [SOLVED] Fastest way to create animations

Author
Message
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 26th Dec 2021 23:00 Edited at: 26th Dec 2021 23:39
Hi there!

I'm new to Appgamekit, and trying to figure out how it all works!

Right now I'm at the point where I create the first animation to a small game.

After researching the topic online, it seems to me that the best way to create the animation loop, is to load every sprite by itself.

For example like this:



However, since this requires you to load every sprite one by one into your project, I was wondering if there is a faster way to create an animation?
Depending on the game size, you could have hundreds, if not thousands of sprites that you need to load into your game. So doing it all this way seems somewhat of a hustle.

To give more exact details about what I'm doing, I'm trying to animate a sprite that I loaded into my scene in the Appgamekit Studio scene editor.

Are there other, possibly faster ways to load the sprites and create an animation?

Thanks for any help!

EDIT:
I might add, in case that the example above IS the standard way of loading animations, is there a way to iterate through every file in a folder in AppGameKit Studio? That could also speed things up...

The author of this post has marked a post as an answer.

Go to answer

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 26th Dec 2021 23:52
Quote: "// Create Your Sprite
spr = CreateSprite ( 1, 0 )

// Load Your Sprite Sheet to AddSpriteAnimationFrame Function
AddSpriteAnimationFrame (1,LoadImage ("Sprites\Characters\Player\Idle\axel_rightidle.png" ) )

// width = width of one sprite in your sheet
// Height = Height of one sprite in your sheet
SetSpriteAnimation ( spr, Width, Height, the max Number of frames Your Sprite Sheet)

// Play Animation Frame
// spr = your ID created Sprite
// fFps = speed run animation
// loop = repeat animation after finish. 1 for loop and 0 for don't loop
// startframe = the first animation frame number
// endframe = the last animation frame number
PlaySprite ( spr, fFps, loop, startframe, endframe )

// Update Screen
do
sync
loop"
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Dec 2021 00:36 Edited at: 27th Dec 2021 01:27
This post has been marked by the post author as the answer.
Quote: "a way to iterate through every file in a folder"

something like:


otherwise, sprite sheets or atlases are preferred where a single image is used:

i know you've looked at part 1 but i'd say part 2 is the best of the 2.

in the end, and if you're like me, you take art in whatever form you can find it and make it work.

craftpix, for example, provides most of their animated sprites as individual frames. after you resize those to fit your needs, they are generally (still) too big to fit in a single sprite sheet. so, you'd use something similar to the code example above.

others, like some of kenney's art are atlases or tilesheets containing frames of various sizes. you'd extract subimages for those. (just noted that pack also has individual frames provided, as well).

then others, like the mole.png above, are uniform frames (of the same dimensions) that allow SetSpriteAnimation().
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 27th Dec 2021 13:34
AGK ships with a sprite sheet maker called ImageJoiner. Take a look in the install folder for a sub folder called Utilities.
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 27th Dec 2021 17:01 Edited at: 27th Dec 2021 18:33
Quote: ""a way to iterate through every file in a folder"

something like:

"

Cool! That's exactly what I've been looking for!
Virtual Nomad, thank you for all the tips and information! You're the best!

Yes, like you, I also have a lot of single sprites that I add to my games.
In general it is a bit simpler for me to work with single sprites.

Looping through the frames works perfectly.

Is there a known way by the way to count the amount of letters in a string? (It could be useful when for example trying to make a difference between '9' and '10' in LoadImage(imageXY.png), so I can add a '0' in front of the '9')

Another important issue for me is the following:
I have two animations for my character sprite. 'Idle' and 'Moving'. Is there a way to store different animations in different sections for a sprite? So I don't have to add all sprites from different animations to the same sprite, and animate the specific frame range, to select the different animations (frames 1-10 for idle, frames 11-20 for moving etc.)?

Quote: "
AGK ships with a sprite sheet maker called ImageJoiner. Take a look in the install folder for a sub folder called Utilities.
"

jd_zoo thanks for the tip!
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 27th Dec 2021 18:15
Animation Sheet Editor ( AnimShed ) is a basic but powerful sprite sheet packer to store a number of sprites into one sprite graphic to load into your code so you can play animations from this one graphic.

In order to create this one graphic to load into your code you would have to put together all your 2D graphics either in a graphics editor or a dedicated Sprite Sheet editor.

AnimShed saves time in this process by automating the loading of your 2D sprites and making it easy to manipulate them and then save them to an image for loading into your game.



https://forum.thegamecreators.com/thread/226299
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 27th Dec 2021 18:30 Edited at: 27th Dec 2021 18:34
Hi Game_Code_here!

AnimShed, which you proposed looks like a real time saver!

Do you know if I can add sprites with different sizes all at the same time into the sheet?
Can I for example load 150x200 animation sprites and 300x220 animation sprites at the same time, without that one of the sprite groups gets scaled and deformed, to adapt to the other?
In that case it would be worth the purchase!
But as far as I understood you cannot do that.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 27th Dec 2021 18:40
You can do that with Texture Packer
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 27th Dec 2021 18:49 Edited at: 27th Dec 2021 20:05
Thanks Scraggle!
Does Texture Packer export for AppGameKit? I mean wouldn't I have to painfully tell AppGameKit the size of each sprite afterwards?

I also discovered this sprite sheet creator 'Free Texture Packer' presented by Jack which seems to do the same thing.
I have no experience with sprite sheets though, and again, I wouldn't know how to tell AppGameKit to split the sprite sheet into the correct sizes and ratios automatically...
Is there an automatic way of doing that?
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 27th Dec 2021 19:40
AGK is fully supported in Texture Packer. It will save a subimages file along with the atlas texture
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 27th Dec 2021 21:26
Quote: "Can I for example load 150x200 animation sprites and 300x220 animation sprites at the same time, without that one of the sprite groups gets scaled and deformed, to adapt to the other?"


Yes you can and you can scale them all to one texture, it is a great program and I use it a lot.

You can use Texture Packer but you can not see what the sprites will look like and you can not do a lot of stuff but it does work.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 27th Dec 2021 21:55 Edited at: 27th Dec 2021 21:59
Quote: "You can use Texture Packer but you can not see what the sprites will look like"

That is true of course. But you can easily fix that by opening your eyes.
All of the sprites are viewable individually or you can select multiple sprites and preview the animation
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 27th Dec 2021 22:29
Am I the only one that uses GIMP with a grid?

For Texture Packer you really need the pro version for the "Max Rect" setting when dealing with animated sprites with odd sized frames but for atlases and tilemaps it is perfect


Quote: "Is there an automatic way of doing that?"


Yes, make the sprite sheet image and apply it to the sprite and use "SetSpriteAnimation" then "PlaySprite"
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 29th Dec 2021 00:49 Edited at: 29th Dec 2021 02:17
So after a quick reply from FuzzyVisions the creator fo Animshed, it seems that you cannot import different sized sprites at once.
Apparently all sprites get normalized into one size, and you have to get them back into size manually, after importing them into AGK.

Otherwise I agree that AnimShed seems to have a lot of cool features.

Scraggle, wouldn't 'FreeTexturePacker' do the same as 'Texture PAcker'?

It seems for now from what I read that simply importing them with a "for" iteration is the simplest way for me and for what I'm trying to do.

A gui based sprite loader that automates this process might be a fine addition to app game kit studio, maybe some day.

Thank you everyone for your input!
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 29th Dec 2021 10:23
Quote: "Scraggle, wouldn't 'FreeTexturePacker' do the same as 'Texture PAcker'?"

I don't know.
I have the full paid for version and it does what you are asking for. I don't know what the limitations are for the free version.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Dec 2021 11:11 Edited at: 29th Dec 2021 11:12
Quote: "So after a quick reply from FuzzyVisions the creator fo Animshed, it seems that you cannot import different sized sprites at once"


I'm sorry, yes you can, unless your confused.

After there loaded there resized to one size. Unless your wanting your animations different sizes which is not a good thing in one sprite sheet.

There is even a option to make all the sprites the same size as any sprite you choose.
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 3rd Jan 2022 01:35 Edited at: 3rd Jan 2022 17:28
Quote: "
I don't know.
I have the full paid for version and it does what you are asking for. I don't know what the limitations are for the free version.
"

OK

Game_Code_Here, yes it actually would be a good thing to have my animations in different sizes in one sprite sheet, if my goal is to save time and load a bulk of sprites into my project at once.

So for now I load my sprites as separate images into my project.
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 3rd Jan 2022 18:17 Edited at: 5th Jan 2022 04:16
Okay, I just made the loading function so much, much better than what I presented before, so I deleted that part from the previous message. Now you just give the folder name and it automatically loads all sprites from the folder, no headache:

So for anyone else to whom loading sprites separately, without creating a spritesheet first, fits better into their work flow, here are the functions I created to speed up the process.
In this code I also included the improvement of PartTimeCoder, who created a function that makes it use image memory more efficiently! Feel free to use with copy and paste:

.

Now you can simply load a folder into an animation, even set the default Animation folder path, with one single command!

This will load ALL files of the specified folder as an animation!
And if you want to play back you simply reference the animation name you created! No need to define the sprite which needs to animate, or the frame range for the animation!


Also I added some additional functions:
"LoadAnimationOffset(sprite_ID,folder,offset)": will load an animation but with an offset, so that it starts at a different frame (defined by the offset parameter). This helps you to randomize your animations, so that multiple sprites don't move at exactly the same way, which looks unnatural.

"LoadGroupAnimation(array_ID,folder)": will load the animation not only for one sprite, but directly for ALL the sprites in an array group at once!

"LoadGroupAnimationOffset(array_ID,folder)": will load the animation, directly for ALL the sprites in an array group at once! And it will automatically create a random offset for each sprite. This way they start animating at a different, random frame!

"PlayGroupAnimation(array_ID,animation,FPS)": will automatically animate ALL the sprites in the array group, with the animation described in the parameters, with only ONE command (given you created the animation array using "LoadGroupAnimation" or "LoadGroupAnimationOffset")

The group animation requires you to create an integer array to save the group animation.

You also have the functions "PlayOnce" (if you don'T want to loop), "StopAnimation(animation)" and "StopgroupAnimation(animationarray)". The latter can be used to stop all sprites of animating in an array group, even if you have started animating them using the standard AppGameKit commands.

For clarity here is one more example:
So let's say you have 20 sprites of a rabbit in your scene (all part of an array group), and you want to load the animation for all 20 rabbits, and then to start the animation for each one. And you want them starting the animation at different frames to look more natural and random.
You can do that with only three commands using these functions!:



P.s.: I didn't have time to pay attention upper and lower case in my functions, so you gotta ignore that
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Jan 2022 11:16 Edited at: 4th Jan 2022 11:20
Nice, but 1 fatal flaw, as with your other post you are not managing image memory very well, or at all!

if you have 20 rabbits the rabbit sprite images are loaded 20 times with unique ID's thus using way more memory than needed, you need to restructure your code to only load an image once, maybe use a type to hold the id and path, in your Load** functions lookup the image path and see if its already been loaded and if it has reuse its ID else load and set its ID in the type array for the next function call

something like this


then just replace your LoadImage commands with LoadAinmationFrame, then each image will only be loaded once no matter how many times you use it.


your full code with my small edits
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 4th Jan 2022 23:55 Edited at: 5th Jan 2022 03:51
'Fatal flaw' is a clear exaggeration, but your function is a cool improvement!
I like that it uses image memory properly and totally automatic, and you don't even have to think about it, just use the same commands!

P.S.: I added your "LoadAnimationFrame" function to my sample code snippet in the message above, so that if people copy and paste it, they have the memory efficient version right away.
Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 5th Jan 2022 03:01 Edited at: 5th Jan 2022 04:16
I tested and made sure that the functions work fine.
When you included your function with mine you needed to add "(folder+filename)" as parameter for it to work, not just "(filename)".
Also I fixed some bugs I found in my group functions and added a "ResetAnimationFolder" function if you want to delete the standard Animation folder path:



I updated my original code snippet of the functions in the previous message as well.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 5th Jan 2022 08:54
Just playing Devils Advocate here:

It seems like you have a good system in place now for loading individual images and creating animation from them but that's not necessarily the way you want to go.
With a system like this, the CPU sends an image to the GPU with then performs a draw call on it, then asks the CPU for the next image and performs a draw call on it then asks the CPU for the next one and performs a draw call on it, then ... ad infinitum. It does all that insanely fast but there is a clear bottleneck between the CPU and GPU and if you are sending 1000's of images to the GPU 60 times per second it could soon become noticeable.
If, on the other hand, you create an atlas texture, the CPU sends that to the GPU and the GPU performs ALL of the draw calls in a single pass.

Like I said, it is all insanely fast but in game dev every little helps. And what performs adequately on your system might be sluggish on someone else's low end system.

In short: What you've got will work but I would still recommend pre-creating atlas textures wherever possible.

Wizard Ranch
2
Years of Service
User Offline
Joined: 24th Dec 2021
Location:
Posted: 9th Feb 2022 20:06 Edited at: 9th Feb 2022 23:57
Hi everyone, I created NEW fully automatic animation functions with html support and spritesheet support!
I used them to very easily create for example all the animations here with only a few lines of code!

Scraggle are you sure it's devil's advocate?
SpriteSheets are the very traditional way of doing it, known by everyone.

I have created 2D games on low end PCs with platforms that run about 100 times slower than Basic/C before. And despite using big sized, photo like graphics and no spritesheets I was never able to run against a threshold where the GPU couldn't handle it (even when using half transparent sprites which eat a lot of processing power).
Nowadays it's just a question of what works best for you and fits better into your workflow. 20 years ago sprite sheets were an absolute necessity.

So after my recent problem with html I created new functions. They are compatible with html and I also added functions for sprite sheets!
So you can directly load a spritesheet as an animation (or group animation) and use it with all the other functions I created. More on it below.

I was given a code part for my script above so that my Animation functions don't load the same image a second time again. That part wasn't working properly at all and also was overkill, because you can save loaded images in a simple integer array[], no type array is needed at all. So I entirely removed it and created my own way of handling it.

To watch out for: Unlike AppGameKit, html is sensitive to upper/lower case, so you need to pay close attention when typing your image paths!

Here is a list of all the functions I created and all the cool things you can do with it.
You only feed the function the imgename. It automatically starts looping through the images, it automatically recognizes weather the numerization starts with 0 or 1. Also it automatically recognizes weather it's a 'bmp','png', or 'jpg' format.


Here is the raw code of the functions. Copy and paste into your project to use:



Check out the code snippet page for more examples.

Login to post a reply

Server time is: 2024-04-19 11:40:50
Your offset time is: 2024-04-19 11:40:50