Qbasicnews.com

Full Version: Sprite loading read/data statements vs image files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
i'm creating a game and i'll have many sprites. i'm currently using the read/data method for a few of them and it works very well. However, i'd like to add many more and instead of creating data statements, i'd like to create a bmp file with all of the sprites i need lined up and load them all in that way. Is this possible without using other libraries or utilities.

i found an example (is it even correct) but it looks like it'll be just one image:
Dim MyPic(100) AS INTEGER
DEF SEG=VARSEG(MyPic(0))
BLOAD "MyPic.bmp",VARPTR(MyPic(0))
PUT (15,15),MyPic

Is it possible to do what i'm asking about?
Well, you cant BLOAD bmp files. You will have to save to a BLOADable file first, using the BSAVE command. I recommend finding a program that converts BMPs to BLOADable files. I imagine you can find one lying about.

Other than that, what you said is correct! You will just have to make sure you GET the sprites from the correct positions in the screen when the BMP is loaded.

Oh, and welcome to the forums =)
Thanks for helping me out.

Ok so i'll find a bmp to bsave file converter and try to figure it out. A few quick things about it since i can't find a clear and concise explanation of what's going on.
How do i traverse the image file and get different sections of it?
What's VARSEG and VARPTR and how do i use it? i take it MyPic is just an array for the sprites but i don't want to just blindly copy code without really understanding what/why it's doing what it's doing.
When the program would be complete and an exe, i'd have to keep that image file with the exe. Is it better to try and keep everything as one file or it's not that big a deal?
Also, how do i DIM the sprite arrays with the the correct number of elements so that i won't be wasteful? i know i can do DIM image(500) but why allocate 500 elements when i'd only need let's say 100.
Lastly, if i've a sprite that's 16 x 16, is it possible to display that sprite in a 20 x 16 arrangement on the screen?

'DEF SEG=VARSEG(MyPic(0))
'BLOAD "MyPic.bsv",VARPTR(MyPic(0))

Thanks a lot for your time. i've read just about every tutorial on this site and others on graphics and haven't been able to completely figure these things out.
DP, speaking of which, I really really want a BSV to BMP converter...
Well.......if you want to resize the sprite do a 'strech' routine


Code:
DIM Shape (length, height) AS INTEGER
DIM Matrix(newlength, newheight) AS INTEGER

FOR x = posx to posx + length
FOR y = posy to posy + height
  Shape(x, y) = POINT(x, y)
  nx = x \ length * newlength
  ny = y \ height * newheight
  Maxtrix(nx,ny) = Shape(x, y)
NEXT
NEXT

This will leave gaps....you may want to use 'LINE -(nx, ny)' fir fix it

Alex~
Quote:Thanks for helping me out.

Ok so i'll find a bmp to bsave file converter and try to figure it out. A few quick things about it since i can't find a clear and concise explanation of what's going on.
How do i traverse the image file and get different sections of it?

Ok, well what I would do is: Open the file and put the entire image onto the screen. Then you just GET whatever sprites you want from the screen. This allows you to use coordinates to choose what part of the file you want. If you dont understand what I mean, just ask And Ill explain this in more depth. You will need code that BLOADs the file to screen, like this:
[syntax="qbasic"]DEF SEG = &HA000
BLOAD "file.bsv"
OUT &H3C8, 0
FOR a = 0 TO 767
OUT &H3C9, PEEK(a + 64000)
NEXT[/syntax]
The part after the BLOAD line is about loading the palette.

Quote:What's VARSEG and VARPTR and how do i use it? i take it MyPic is just an array for the sprites but i don't want to just blindly copy code without really understanding what/why it's doing what it's doing.
Thats a good attitude to take. as far as i know, the "DEF SEG = VARSEG(pic(0))" changes the current memory segment to the "pic" array. Then the "BLOAD "MyPic.bsv",VARPTR(Pic(0))" loads the file into the current memory segment, thus putting it into the array.

Quote:When the program would be complete and an exe, i'd have to keep that image file with the exe. Is it better to try and keep everything as one file or it's not that big a deal?
It is actually better to have external files. That way, you can make small changes such as new textures or new sprites without having to change the code or recompile the program. You could even mod your program to make it look completely different if you wanted, for example different themes. They could be done just by changing the external image files.

Quote:Also, how do i DIM the sprite arrays with the the correct number of elements so that i won't be wasteful? i know i can do DIM image(500) but why allocate 500 elements when i'd only need let's say 100.
Well, if you want to save a sprite that is, say 16x16, then you want an array which has 16*16 subscripts. so that would be just DIM sprite(16*16) or DIM array(256). This is sufficient for GETting

Quote:Lastly, if i've a sprite that's 16 x 16, is it possible to display that sprite in a 20 x 16 arrangement on the screen?
If you mean you want to scale the sprite, to make it appear larger than the actual saved sprite is, then that is perfectly possible, although you will have to write the code for it. if the sprite is in a GETed array, this is a lot harder. I would reccomend sticking to the normal size.
Quote:Thanks a lot for your time. i've read just about every tutorial on this site and others on graphics and haven't been able to completely figure these things out.
Sure thing. Loading graphics and using external graphics is a right pain in the backside, so dont hesitate to come back and ask more questions, no matter how simple you think they might be =)
The part about loading the entire image onto the screen and getting what i need then is great and makes perfect sense. Thanks a lot.

The separation of files is what i figured but i wanted to make sure.

The part with the sprites and memory allocation is what concerns me. When i was doing 16x16 sprites, i could allocate (65) and it worked fine. Once i started using setvideoseg, (65) wasn't enough and i had to do more. Now you're saying i should just do (256). Is there a way to calculate exactly what it needs or should i not concern myself with it? The reason i ask is because i want to have an array of SPRITES. ie heroSprite(0) is the hero going up heroSprite(1) is the hero going down, etc...

As for displaying 16x16 as 20x16, the image would be GETed. Someone posted a sample bit of code but i havent been able to try it out yet. Would what they said work?
Ok, well I know what you mean about the memory subscripts. To be honest, I dont really understand it, for example sometimes you only need to dimension half the subscripts that it would appear you need. Hopefully someone else can shed some light... nek, nath?

Ok, now you want an array of sprites. Cant be done I'm afraid. Only if you create your own type of array for holding the sprites. Then you could so such things as -

DIM sprite(16,16,5)
THis would allow you to hold up to 6 (includes 0) 16x16 sprites. (technically it could hold up to 17x17 sprites because of including the zero.

But this method doesnt work with GET.

Try Rellib. Made by our very own Rel ;D It allows you to load PP sprites and have an array of sprites!

The sample code that Oz posted wouldnt work with a GETed array. The GET format works slightly differently from a plain old sprite(x,y) array. You would have to find someone who knows the format who could help you write a scaler for use with GETted arrays.

-=dark=-
*Cough*No-one here knows me as Oz*cough*
Ok im trying to use the sample you gave about loading the entire image to the screen and then GETting what i need.

Code:
screen 13
DEF SEG = &HA000
BLOAD "c:\qb45\tut\sprite.bsv"
OUT &H3C8, 0
FOR a = 0 TO 767
     OUT &H3C9, PEEK(a + 64000)
NEXT

i get a blank screen. i know the bsv file is good so what am i missing?
Pages: 1 2 3