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 DBPro Corner / Creating / Animating Sprites

Author
Message
kkun
15
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 11th Jun 2009 08:56
I've searched all over the forums and many have small snippets of codes and talking about certain functions that these commands do but it doesnt answer some specific questions i have myself. If someone could reply i would be very greatful.

Basically i used a sprite sheet and it just plays the sprite sheet scrolling the sprite sheet at one location.

Ive seen people talking about the CREATE ANIMATED SPRITE Sprite Number, Filename, Across, Down, Image Number

I noticed people talking about the across and down, Is that how many images are in a file? I saw a post saying how many images it was and not pixels. Does that mean DBpro knows when or how many images are in a file?

With this it leads to another question. Let's say i put a walk cycle of 5 different frames into one single file across. Would [Create Animated Sprite 1, "filename.bmp", 1, 5, X <<<<<] be correct? and what do i put for that X? Did i have to [Load Image] image first?

Does this make the image automatically move when i make my images set to certain keys or will it animate even if it stood in one place?


I am really confused with this and as i said i would be very greatful if anyone could clarify this.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 11th Jun 2009 18:35 Edited at: 11th Jun 2009 18:56
Quote: "I noticed people talking about the across and down, Is that how many images are in a file? I saw a post saying how many images it was and not pixels. Does that mean DBpro knows when or how many images are in a file?"


Yes, it's by images but it can only determine how many images there are by the across and down numbers you tell it. What Darkbasic does is takes the horizontal size of the image and divides it by the number of images you say are across to determine how many pixels to grab for the horizontal to grab each image. It does the same for vertical (takes the vertical size and divides by the number of down images).

So with the attached image there are 14 across and 1 down. The horizontal size is 435... 435 / 14 = 31. The vertical size is 32... 32 / 1 = 32. So Darkbasic knows to grab 14x1=14 images at 31x32 pixels for the animated sprite. If your images are lined up properly it'll work perfectly.

Quote: "With this it leads to another question. Let's say i put a walk cycle of 5 different frames into one single file across. Would [Create Animated Sprite 1, "filename.bmp", 1, 5, X <<<<<] be correct? and what do i put for that X? Did i have to [Load Image] image first?"


No it would be "CREATE ANIMATED SPRITE 1,"filename.bmp",5,1,X" the 5 and 1 are switched because it's 5 across and 1 down. The X is the image number you want to use to save the whole animation. TGC made it simple for us and put everything we need for grabbing images for animation in one command instead of us having to grab the images ourselves with multiple lines of code using multiple small images.

Quote: "Does this make the image automatically move when i make my images set to certain keys or will it animate even if it stood in one place?"


No that requires another command called PLAY SPRITE which you tell which frame number to start on, which to end with, and how much of a delay you want. Without the code seeing PLAY SPRITE the image wouldn't animate and stay on a single frame.

Those commands really just makes it easier on us to make animated sprites... there is always the old way:


But the new way is so much easier, does exactly the same thing, and takes a lot less code:


Attachments

Login to view attachments
kkun
15
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 12th Jun 2009 08:30
Quote: "So with the attached image there are 14 across and 1 down. The horizontal size is 435... 435 / 14 = 31. The vertical size is 32... 32 / 1 = 32. So Darkbasic knows to grab 14x1=14 images at 31x32 pixels for the animated sprite. If your images are lined up properly it'll work perfectly. "


Saying this does that mean i really have to line up my sprites exactly the right distances apart? You said as an example its a 32x31 pixels. If there was extra pixels in between would DBpro pick that up or will it cut a bit off the next sprite because i have moved a few images across a few pixels?

If so does that mean if i have sprites of different lengths they should be together? Eg Fireball sprite that is 32x50 pixels with another fireball sprite the same length and not another sprite that is only 32x32?

Thanks for that quick reply, ill go test out what you've showed =] ill be back though if i have more troubles.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Jun 2009 17:03
Quote: "Saying this does that mean i really have to line up my sprites exactly the right distances apart? You said as an example its a 32x31 pixels. If there was extra pixels in between would DBpro pick that up or will it cut a bit off the next sprite because i have moved a few images across a few pixels?"


Yes, Darkbasic has no way of knowing there are extra pixels between each image. It just assumes their right next to each other so if you have extra pixels it'll throw the images off a bit. I noticed a slight difference in my own image too... a small wobble of the mouse one pixel left and right. I determined it to be because it was an odd number at the horizontal size of the image (because dividing by 435 resulted in 31.0714). All images must have even numbered sizes for it to line up properly. Check out the attached image that's 434x32 with boxes around each frame to show where Darkbasic grabs each image. This image is a .png so change the filename to "MouseAnimation.png".

Quote: "If so does that mean if i have sprites of different lengths they should be together? Eg Fireball sprite that is 32x50 pixels with another fireball sprite the same length and not another sprite that is only 32x32?"


It just depends on how you want to do it. Generally you make a box big enough to hold the max size of any firepower you want. Say you're making a space invaders game and you want it to have a starting laser fire coming from the center of the ship... but later you want to change that ship to have 2 additional beams of lasers. You make a box big enough to hold 3 laser beams but center it so that you can erase the two end lasers (in your sprite sheet) and use the middle laser for the starting laser fire. You do that so you don't have to change the x and y of the laser fire because weather or not it's firing a single laser beam or three of them the x and y stays the same. So if you add even more weapons fire for upgrades you just change the images used and don't have to change the x and y of the bullet code. If this example is confusing just tell me and I'll make some images to explain better.

Attachments

Login to view attachments
SWokt0r
15
Years of Service
User Offline
Joined: 19th Jul 2009
Location: At the end of the rainbow...
Posted: 23rd Aug 2009 11:10
Does this mean that you have to line up the images in the code and that when you run the code the images will be playing on top of each other?

Angola - The game
Coming soon
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Aug 2009 01:54
Line them up properly in the image and you won't have to line them up in code (which would be a lot more trouble). Notice the image on the the last message of mine. It's got the mouse pointer in the upper left corner of each box. If the mouse was moved over a bit in a few of those boxes it wouldn't look good because there would be a wobble too. If everything lines up it all looks good and animates properly.

SWokt0r
15
Years of Service
User Offline
Joined: 19th Jul 2009
Location: At the end of the rainbow...
Posted: 26th Aug 2009 17:32
Right, thanks.

Angola - The game
Coming soon

Login to post a reply

Server time is: 2024-09-28 10:23:15
Your offset time is: 2024-09-28 10:23:15