Qbasicnews.com
May 26, 2020, 05:11:34 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Sprite loading read/data statements vs image files  (Read 5402 times)
annunaki10
New Member

Posts: 23



« on: June 02, 2004, 04:13:29 PM »

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?
Logged
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #1 on: June 02, 2004, 04:40:18 PM »

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 =)
Logged
annunaki10
New Member

Posts: 23



« Reply #2 on: June 03, 2004, 11:07:44 AM »

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.
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #3 on: June 03, 2004, 11:39:48 AM »

DP, speaking of which, I really really want a BSV to BMP converter...
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Oz
I hold this place together
*****
Posts: 923



« Reply #4 on: June 03, 2004, 01:02:05 PM »

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~
Logged
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #5 on: June 03, 2004, 02:16:04 PM »

Quote from: "annunaki10"
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 =)
Logged
annunaki10
New Member

Posts: 23



« Reply #6 on: June 03, 2004, 03:22:51 PM »

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?
Logged
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #7 on: June 03, 2004, 04:09:00 PM »

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 Grin 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=-
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #8 on: June 03, 2004, 06:02:28 PM »

*Cough*No-one here knows me as Oz*cough*
Logged
annunaki10
New Member

Posts: 23



« Reply #9 on: June 04, 2004, 12:47:55 AM »

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?
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #10 on: June 04, 2004, 09:31:18 AM »

Quote
Code:
OUT &H3C8, 0
FOR a = 0 TO 767
     OUT &H3C9, PEEK(a + 64000)
NEXT


Does this code search the screen adapter and 'POKE's it on the screen?
If it doesn't, then you just have to display it......

Otherwise, just use VARPTR and VARSEG .....tho u need to know the exact array size of the image....

You may want to use a compression routine, and add 2 files....one holds the array, and the other is the number of indexs

Alex~
Logged
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #11 on: June 04, 2004, 10:49:51 AM »

Quote from: "Alex_at_EverNever"
*Cough*No-one here knows me as Oz*cough*


=/  You told me to call you oz when I called you Alex. What do you want to be called!?



The actual code... hmm. Ok. Scrap the
Code:
OUT &H3C8, 0
FOR a = 0 TO 767
     OUT &H3C8, 0, PEEK(a + 64000)
NEXT

I think this was actually for a BSAVEd file with the palette included. Try it without that bit, and see what you get. If you do get an image, but the colours are wrong, then you may want to think about making your own palette file. You would do this by saving each of the colours from 0 to 255 into a file. The colours would be saved using the R G and B components.

To change a colour to another colour with components R G and B, use this code:

OUT &H3C8, colour
OUT &H3C9, R
OUT &H3C9, G
OUT &H3C9, B

so, to change the entire lot of colours, you would put it inside a FOR, NEXT loop, ranging from 0 to 255. Each time you could read the RGB components from file and set the colour accordingly.
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #12 on: June 04, 2004, 11:07:32 AM »

Quote from: "Alex_at_EverNever"
Well.......if you want to resize the sprite do a 'strech' routine

Stretch... without filtering... hrmmm Wink I recently found out how filtering works, and I think I can also make it a QB version... some time (LINEAR and BILINEAR (?)). Btw, I didn't read stuff about it, I just came up with my own algo.

Zack: it's already in the CPP Image Module Code, which I'll send to you soon Smiley
Logged
annunaki10
New Member

Posts: 23



« Reply #13 on: June 04, 2004, 03:38:56 PM »

You know what, all this poking and outing is driving me nuts. i thought this would be a simple task but i just can't get it to work or i dont get it. i made a BSV with a program, bsvbabel i believe, and it even has a loader so i know it works. i'm looking through the source to try and find what it is exactly that i need (that scrolls the image along the screen). There's VARSEG VARPTR all of this stuff and i can't find much explanation of these things anywhere. The QB book i have at home is quite old and i dont think it has much mention of it.  The closest i got was using this snippet:
Code:

DIM Cube(1 TO 675)
SCREEN 13
DEF SEG = VARSEG(Cube(1))
BLOAD "sprite.bsv", VARPTR(Cube(1))
DEF SEG              
PUT (80, 10), Cube

i got this sample from F1 about BLOAD. The only problem is that while most of the image is clear, some of it is off. ie, the sprites dont all line up properly and parts that should be together aren't. i know the file is good cause when i test it with the utility that bsvbabel comes with, it all looks good.
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #14 on: June 04, 2004, 03:46:18 PM »

Are ya sure that the BSAVEd sprite in sprite.bsv was taken in SCREEN 13?
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!