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.

Newcomers AppGameKit Corner / Animating Sprites

Author
Message
kebang
10
Years of Service
User Offline
Joined: 24th Feb 2014
Location:
Posted: 25th Jul 2021 10:43
loadimage (1,"starts.png"):createsprite(1,1)
loadimage (20,"snail.png",1):createsprite(20,20)
loadimage (21,"extsnail.png",1):createsprite(21,20)
do
x=x+1
setspriteposition(20,x,400)
setspriteposition(21,x,400)
sync()
loop
Trying to get sprites 20 and 21 to repeatedly replace each other, but they both remain visible so the effect of animating them doesn't work.
There must be a way to do this- I did achieve this in DB many years ago, but I must be missing something

Attachments

Login to view attachments
hendron
8
Years of Service
Recently Online
Joined: 20th Dec 2015
Location:
Posted: 25th Jul 2021 14:30
If you want to hide or show a sprite, you need to use SetSpriteVisible, However I'd recommend having a look at the built in Sprite Animation Commands.


PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 25th Jul 2021 15:36
Why not use AddSpriteImage and PlaySpriteAnimation?
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 25th Jul 2021 22:58
@PartTimeCoder.... see what I was saying earlier? People will jump to forums and chatrooms with their questions instead of making the slightest effort to search for an answer themselves


@kebang... Look at your code. You are creating two sprites. You can't expect them to act as one sprite with different frames. There are commands, in the online help, which are going to take care of this for you. You can either animate them with AGK's own commands, or you can do like I do and code your own animation routine so you have more control over things. Both are completely valid. But you have to be willing to read some documentation and do some experiments by yourself at some point. In the last few days you've been posting daily about super basic things that you fully understand once we point you to the online help doc. I mean come on my man, you don't need us to point you at the help file every time

But in the interest of not being a total arse like I usually am...

What you want to do is have all your animation frames in a single image. It's what's usually referred to as an animation strip. Let's say your sprite is 50 pixels wide by 50 pixels high and has 5 frames of animation. You can just create a 250 pixels x 50 pixels image and store each frame of the animation next to one another. That way you can do this:



That will load your animation strip image. Then it will create a sprite with it. Then it will give you how big is each frame, and how many of them there are. In this case, 50x50, and 5 frames.

You can then set that sprite's animation frame using SetSpriteFrame(MySprite, FRAMENUMBER)


-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us

Login to post a reply

Server time is: 2024-04-26 14:08:54
Your offset time is: 2024-04-26 14:08:54