Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading sprites
#1
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?
Reply
#2
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.
Reply
#3
Doesn't work =\
Reply
#4
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?
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#5
Yes, that's what I mean :roll:
Reply
#6
I don't know what I was thinking... :roll:
Reply
#7
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...
Reply
#8
'$dynamic
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#9
Ok, and where exactly do I put that? 'Cause I can't get it to work...
Reply
#10
anywhere before the array DIMs
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)