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.

2D All the way! / How would you animate a sprite?

Author
Message
Eminent
13
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 9th Aug 2010 05:18
Dark Noob Games are making a Space Invaders game and Im in charge of graphics. So how would I animate a sprite? I have attached a image of what I have so far. I want it to show frame 1 then frame 2 then frame 1 again and so on. How would I animate a sprite to do something like this?

Attachments

Login to view attachments
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 9th Aug 2010 12:59
You could have a sprite sheet, then either grab each part as a seperate image, or UV map the sprite or plain to suit the frame you want.
It's all good, because you probably want an animated explosion, or maybe even firing too, so drawing it all out on a 4x4 grid for example is a good start. If you are using sprites then the SET SPRITE TEXTURE COORD command will let you take over UV mapping, or there is also the automatic sprite animation system, never used it but it might save you a bit of time. If you are pasting the images onto the screen, then you have to grab each sprite frame individually, then paste whatever frame on the screen. If you are using a plain, then I can post a plain UV mapper function, you just specify the grid size, and grid position of your tile on the tile sheet and it does the rest.

Health, Ammo, and bacon and eggs!
Eminent
13
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 9th Aug 2010 19:59
Can you post a code snippet because being the newb I am, I under stood just about nothing that you said.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 10th Aug 2010 06:07 Edited at: 10th Aug 2010 06:12
Quote: "So how would I animate a sprite?"

In a nutshell, create the images needed to give the illusion of movement. Code it so that the images are played in a fluent manner.

You could use the CREATE ANIMATED SPRITE command, but I normally do not use it myself, as there is at least one issue with it. I like to do like Van B's first idea, make a sprite sheet and pull the images off of it within a game.

Here is some example code that may help you:



It is a simple program to show you how to pull images off of a bitmap. Once grabbed, the images are used by three sprites to move horizontally back and forth across the screen. The bitmap is attached to this post.

EDIT: It is worth noting that the sprites are not animated. This example is only intended to show you how to pull images off of a bitmap.

So many games to code.......so little time.

Attachments

Login to view attachments
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Aug 2010 07:54 Edited at: 10th Aug 2010 07:56
There are two methods that are basically the same. The manual method which grabs separate images and you cycle those images like animation frames and the CREATE ANIMATED SPRITE command which does everything automatically for you.

The Manual Method:


The CREATE ANIMATED SPRITE method:


Both of these methods do the same exact thing but the manual method you have to grab your own images, create a timer, and make code to change the frames manually. CREATE ANIMATED SPRITE does the image grabbing for you and it automatically animates the sprite with the PLAY SPRITE command. The only difference is you have to be very careful with the image you use. The size of the image has to be even otherwise you'll get a wobble in the animation.

CREATE ANIMATED SPRITE takes the size of the image and divides it by the number of frames you say is in that image so it can determine how big each frame needs to be... if it's an odd number it doesn't grab it just right. The attached image is 64x16... so when you tell Darkbasic to make it an animated sprite with 2 frames across and 1 down it knows to divide 64 by 2 and divide 16 by 1 to get each frame size at 32 by 16 pixels. If the image was odd like 63x16 it wouldn't look as good because it didn't divide the frame size evenly.

I also noticed that you used .jpg in your image. It's better to use .png so it's easier to work with (doesn't change colors around like .jpg) and allows you to use transparencies.

Edit: I changed the image to use orange instead of white so you can see it with the view button.

Attachments

Login to view attachments
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 10th Aug 2010 08:09
Like I said, I don't normally use CREATE ANIMATED SPRITE. I have yet to get .pngs to show transparency correctly with them (you obviously have, but the commands just don't seem to work right for me and in searching I saw where others had the same issue). Another thing with CREATE ANIMATED SPRITE is that if you are playing a sprite and switch directions (and animations), it tends to play all of the animations before it gets to the right ones. Maybe you have figured out a different work-around than I have for this. From my experience, even though .pngs tend to be smaller, they take a little longer to load (which is really only noticeable in larger programs), so I do not use them like many do.

Quote: "It's better to use .png so it's easier to work with (doesn't change colors around like .jpg) and allows you to use transparencies."

Because the forum uploads .jpgs better I used that format. I use the .dds format for most of what I do.

So many games to code.......so little time.
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Aug 2010 08:54 Edited at: 10th Aug 2010 09:41
Quote: "Like I said, I don't normally use CREATE ANIMATED SPRITE."


That message wasn't aimed at you specifically... it was aimed at Eminent. I didn't like using CREATE ANIMATED SPRITE either at first but it grew on me.

Quote: "it tends to play all of the animations before it gets to the right ones."


Yes it is rather annoying but if you use the SET SPRITE FRAME you can jump to the starting frame you want so the next time the PLAY SPRITE command is seen it'll start on the desired frame without playing through all the other frames.



In the above snip use the spacebar to switch directions. Normally I would just use MIRROR SPRITE since running right and running left are the same but I added running left to show SET SPRITE FRAME in action.

Quote: "Because the forum uploads .jpgs better I used that format. I use the .dds format for most of what I do."


Eminent was using .jpg too. I prefer .pngs but .dds is a decent format too.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-19 16:30:09
Your offset time is: 2024-04-19 16:30:09