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.

DarkBASIC Discussion / sprite sheet help

Author
Message
sirsiddy
19
Years of Service
User Offline
Joined: 15th Jan 2007
Location:
Posted: 6th Mar 2007 02:10
Iv been reading up on sprites and come across sprite sheets, and found one that was jesus lol. Im just a little confused on how you get those sprites into darkbasic? do you use photoshop to cut em out save them as a bmp then load them into darkbasic? and to animate them do you just hide all sprites show a sprite, hide all again, show another? Im kinda confused
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Mar 2007 19:47
Hello,

Basically, the final output that creates a sprite is changing an image to a sprite. When I use the term 'image' I'm referring to how DarkBASIC treats a picture that it will use as a texture or a sprite. This is different than what DarkBASIC refers to as a bitmap. A bitmap in DarkBASIC is a screen. You can think of it as a chalkboard where your images or 3d objects are drawn (don't confuse this with the .bmp format of a picture). You can draw on any of 32 different bitmaps, but the one that you can see is bitmap 0. This is the main viewing screen. Every picture or 3d object that is created can only be seen when displayed on bitmap 0. What good are bitmaps that you can't see? Well, you can use these to draw out of view so that your work area isn't displayed on the main screen. Once your done with your drawings or updates, you switch back to the main screen and only display the changes that you want visible.

That's the basics, now onto your sprite sheet.

Like I said before, to create a sprite, you need an image. On a sprite sheet, there are several pictures that usally represent a different animated position of whatever is drawn. Each one of these pictures can be considered an image. The task is to get the image to the sprite. Now, to make a sprite appear to animate, you have to change the sprite's image. But how do you tell a sprite to change its image? That's very easy: The SPRITE command is all you need. SPRITE number,x,y,image number. If you want a single animated sprite, you don't have to change the sprite number, you only have to change the image number. The next question would be: "but where do I get these image numbers?"

This is where you have to decide what is the best method for you. You could divide your sprite sheet in photoshop into several files, each one representing a single frame. Then you can load each frame into an image number in BarkBASIC using LOAD IMAGE filename,image number. You assign the image number to each picture as you load it. Assuming you create 50 separate files and then loaded them as 50 separate images you could set up a simple loop to animate your sprite:



That will cycle through all of the images that you loaded and assigned to an image number.

Another way would be load the entire sheet as a bitmap, and then use the GET IMAGE command to select a specific area on the bitmap and assign it an image number. So if your sprite sheet had 2 pictures across, and 2 pictures down, and it was 200 x 200 pixels wide, you would use something like:



It would be more efficient to use a loop and calculate the x and y positions based on the size and position of each picture.

Once you have the pictures assigned to images numbers, you just cyle through the images for the sprite like in the previous example:



You don't need to hide and show the sprite. Just cycling through the image numbers will change the sprite's appearance.

Enjoy your day.
sirsiddy
19
Years of Service
User Offline
Joined: 15th Jan 2007
Location:
Posted: 7th Mar 2007 00:24
Wow thx Latch that helps alot
Quisco DaLuse
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 9th Mar 2007 14:12
To build on what Latch has said, you could also store the x/y coordinates within a data statement, read the coordinates and grab the images.
An example would be:

[/code]
restore IMG_DATA
for img=1 to 4
read x1,y1,x2,y2
get image img,x1,y1,x2,y2
next img


IMG_DATA:
` image 1
data 0,0,100,100
` image 2
data 101,0,200,100
` image 3
data 0,101,100,200
` image 4
data 101,101,200,200
[code]

This would help if you have many images to grab or if they are going to vary in size.

You idiots! You've captured their stunt doubles!

Login to post a reply

Server time is: 2026-07-06 12:11:40
Your offset time is: 2026-07-06 12:11:40