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 Classic Chat / [SOLVED] Custom Sprite Animations

Author
Message
gosukiwi
AGK Tool Maker
3
Years of Service
User Offline
Joined: 24th May 2020
Location: Argentina
Posted: 27th May 2020 22:58
Hi all, one question.

Say I have a spritesheet with 4 sprites in it, defining a simple walking animation. I can easily play with with PlaySprite, no problem there.

The thing is, the animation is supposed to be played in this order: 1 -> 2 -> 3 -> 4 -> 3 -> 2 (and then loop, starting from 1). PlaySprite does not allow for this AFAIK.

One way to do this would be just creating a bigger sprite sheet, with 6 sprites instead of 4, but defining which frames each animation uses can be helpful for saving resources too. Is there a way you can define the frame order for animations?

Cheers.

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

Go to answer

swift-au
3
Years of Service
User Offline
Joined: 13th Apr 2020
Location:
Posted: 28th May 2020 03:40
If you wish to use PlaySprite(), then no, I believe you would either need to use AddSpriteAnimationFrame (slower) , or do as you suggest and duplicate frames 3 and 2 in your sprite sheet.
Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 28th May 2020 07:00
You can edit the file by specifying the desired sequence.


Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 28th May 2020 11:01
This post has been marked by the post author as the answer.
The PlaySprite() command does allow you to play a non linear set of image frames as part of an animation. Its just more complex to set it up. You can do this with one Atlas image with the 4 frames on it. These can be played in the 1,2,3,4,3,2 order as you have said.

You cant use SetSpriteAnimation() as that only allows you to set up frames that are in order Ie 1,2,3,4
Instead, you have to use AddSpriteAnimationFrame() for each frame you want.

1) Load up the atlas image for your sprite
2) Load up subimages for the 4 images in that file (1,2,3,4) - LoadSubImage() - you will need a subimages file for your atlas image to use this
3) Setup the animation by using AddAnimationFrame() adding each frame in the order you want it ...Add frame 1, then 2, 3 4,3,2 (Now you have 6 frames of animation but using 4 images)
4) Then just use playsprite same as before.

Its not really any 'slower' using this method as you are still using one atlas single atlas image and AppGameKit is just changing UV coords

I have attached an example project which sets up 6 frames of animation but using 4 images in the Atlas image file and plays them in the order you wanted.

Attachments

Login to view attachments
gosukiwi
AGK Tool Maker
3
Years of Service
User Offline
Joined: 24th May 2020
Location: Argentina
Posted: 28th May 2020 17:00
Thanks everyone for replying, and @Bengismo nice! That seems to be the way to do it

Login to post a reply

Server time is: 2024-03-28 11:24:58
Your offset time is: 2024-03-28 11:24:58