Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sprites(file formats, loading, ...) in FB?
#1
I want to know which libraries or routines I should use to store sprites into an integer array(s) and from what type of image file format(s) these sprites should be loaded. How to load and store sprites? I can't port Pixel Plus 256 sprite loading subs to FB since one of them contains DEF SEG statement and I don't know if that can be fixed or how. I wouldn't mind if someone could explain me in more simple terms why DEF SEG is not supported and not needed in 32-bit mode.

I so don't want to abandon Pixel Plus 256 so I need a routine that can load that format(PUT) into an integer array in FB.

I want to avoid using BMP images which have all the sprites or tiles inside them and then having to use some annoying way to load and paste sprites onto screen. I'll be honest, I don't like the way SDL solves the sprite issue(at least the way BasetFurry does it in his tutorial).

Here are the two subs from Pixel Plus 256 I mentioned if you don't know about them.

Code:
'* InitImageData() subroutine:
'* Initializes an integer array with image data - this must be done before
'* displaying an image using the PUT(graphics) statement. The calling value
'* of FileName$ dictates whether the data should be read directly from an
'* image file or from DATA statements (see below).
'*
'* Parameters:
'*    FileName$ - The name of the image file to load. This must include the
'*                path to the file if it does not reside in the current
'*                directory. If FileName$ is an empty string (""), image
'*                data is read from DATA statements.
'* ImageArray() - Dynamic, integer array to hold the image data.
'*
'* Note: Before calling InitImageData() to initialize images from DATA
'*       statements, use an appropriate RESTORE statement to ensure the
'*       correct DATA statements are read.
'*
SUB InitImageData (FileName$, ImageArray())

    IF FileName$ <> "" THEN
        '***** Read image data from file *****

        'Establish size of integer array required.
        FileNo = FREEFILE
        OPEN FileName$ FOR BINARY AS #FileNo
        Ints = (LOF(FileNo) - 7) \ 2
        CLOSE #FileNo
        REDIM ImageArray(1 TO Ints)

        'Load image data directly into array memory.
        DEF SEG = VARSEG(ImageArray(1))
        BLOAD FileName$, 0
        DEF SEG
    ELSE
        '***** Read image data from DATA statements *****

        'Establish size of integer array required.
        READ IntCount
        REDIM ImageArray(1 TO IntCount)

        'READ image DATA into array.
        FOR n = 1 TO IntCount
            READ x
            ImageArray(n) = x
        NEXT n
    END IF

END SUB

'* MakeImageIndex() subroutine:
'* Constructs an image position index for the images held in an image array.
'*
'* Parameters:
'* ImageArray() - Dynamic, integer array holding images to be indexed.
'* IndexArray() - Dynamic, integer array to hold the index for images in
'*                ImageArray().
'*
SUB MakeImageIndex (ImageArray(), IndexArray())

    'The index will initially be built in a temporary array, allowing
    'for the maximum 1000 images per file.
    DIM Temp(1 TO 1000)
    Ptr& = 1: IndexNo = 1: LastInt = UBOUND(ImageArray)
    DO
        Temp(IndexNo) = Ptr&
        IndexNo = IndexNo + 1

        'Evaluate descriptor of currently referenced image to
        'calculate the beginning of the next image.
        x& = (ImageArray(Ptr&) \ 8) * (ImageArray(Ptr& + 1)) + 4
        IF x& MOD 2 THEN x& = x& + 1
        Ptr& = Ptr& + (x& \ 2)
    LOOP WHILE Ptr& < LastInt

    LastImage = IndexNo - 1

    'Copy the image index values into the actual index array.
    REDIM IndexArray(1 TO LastImage)
    FOR n = 1 TO LastImage
        IndexArray(n) = Temp(n)
    NEXT n

END SUB

'this is how the subs can be used(example):
SCREEN 13
DEFINT A-Z

REDIM Set2Data(1 TO 1)
REDIM Set2Index(1 TO 1)

CALL InitImageData(Path$ + "SOMEFILE.PUT", Set2Data())
CALL MakeImageIndex(Set2Data(), Set2Index())

PUT (x, y), Set2Data(1), PSET
I just want to be able to use put video functions, SDL's or any other, on the most similar way
I used RelSprite with sprites stored into an integer array, if that's possible. RelSprite worked so great with PP256 PUT format. All that rect s-h-i-t in SDL seems too clumsy to me. At least now. I still don't know much about SDL.


Thanx in advance.
Reply
#2
I wanna know this too... And how do I put sprites on the screen using RelSprite with FB? It's not the same as in QB
Reply
#3
bload "image.bmp"

get (x1, y1)-(x2, y2), array

...:O


i know i know... lol. but you really should learn how to index multiple sprites in a single array. its as easy as multiplying by the number of indices...
Reply
#4
Yes, you were very helpful. I'll go learn now. By myself. Sad

KoVe, QB libraries don't work in FB. Sadly. If RelLib was ported to 32-bit and would feature SCREEN 12 mode it would be the most popular library in the programming world.

This sprite issue is the main obstacle to my transition to FB.
Reply
#5
i think barok an/or rel has written conversions from pp256 to a format fb can use. not sure on it though. i personally always did it all from scratch, so... i cant really help you much wit the whole pp256 thing, sorry
Reply
#6
Yes, I spotted few threads about those conversion(s). But it doesn't seem to be something fully stable and easy to use. Well, I didn't saw some sort of download. This could be a good topic for an article in QB Express.

BTW people, you can recommend me alternatives. I just can't belive there is nothing similar to PP256 in 32-bit world. I just can't grasp the idea that everyone imports sprites in their games on that stupid way by putting the sprites in BMP, GIF or whatever images and then butchering them inside the compiler.
Reply
#7
FBs BLOAD loads the same format as qbs BLOAD, so you can still use pp256s format. Try baroks code, it seems to be the same code as the one you posted, but ported to FB and not so 'clean' Smile
You cant load FBs BSaved files with qb, tho

edit:
Baroks code http://forum.qbasicnews.com/viewtopic.php?t=9083, just copy and paste

Bye the way, I like "butchering them inside the compiler" :rotfl:
Reply
#8
Ummm, PP256's tilesets are nothing more than a giant bload with pictures one after the other...those SUB's butcher them inside the compiler.

Use Photoshop, The Gimp (or Gimpshop), or the hundreds of other 32-bit freeware graphics applications (http://www.freewarehome.com). I would recommmend using a BMP with a bunch of sprites and GETing them, as shown above.
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#9
Quote:FBs BLOAD loads the same format as qbs BLOAD, so you can still use pp256s format. Try baroks code, it seems to be the same code as the one you posted, but ported to FB and not so 'clean' Smile
You cant load FBs BSaved files with qb, tho

edit:
Baroks code http://forum.qbasicnews.com/viewtopic.php?t=9083, just copy and paste

Bye the way, I like "butchering them inside the compiler" :rotfl:

You'll never get me to code clean! NEVER!!!

Just a note, my tile loading routines start loading from 0 instead of 1. (i never really saw the reason why chadwick's routines start from 1 instead of 0) But the tile indexer starts from 1 for compatibilitiy reasons. This shouldn't effect your code though.
Jumping Jahoolipers!
Reply
#10
This better work or else... Tongue
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)