Qbasicnews.com

Full Version: Loading sprites
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Ok, so I made a sprite with PP256 and now I'm trying to load it with the well-known code:

Code:
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

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



REDIM Sprites(1 TO 1)
REDIM SpritesIndex( 1 TO 1)

InitImageData "C:\QB\PP256\IMAGES\HL.put", Sprites()
MakeImageIndex Sprites(), SpritesIndex ()

But at this point:
Code:
Temp(IndexNo) = Ptr&

I'm getting a "Subsrcipt out of range" error. This is a really simple question, but I just couldn't get it right...Anyone?
Only time that could happen is if you have more then 1000 images in one file...

Try printing out IndexNo to see where it crashes.
(Should be 1001)

Just add a PRINT IndexNo right before the crashing code.
Doesn't work =\
What do you mean "it doesn't work"? Do you mean that you can't see the PRINT because it already went back to the IDE or what?
Yes, that's what I mean :roll:
I don't know what I was thinking... :roll:
Hmm...ok I got it now, it crashes at 1001 (what a surprise! =p) But I haven't got more than thousand images in one file...
'$dynamic
Ok, and where exactly do I put that? 'Cause I can't get it to work...
anywhere before the array DIMs
Pages: 1 2