|
Post by tbird on Sept 1, 2018 7:47:34 GMT -6
Hey Noob, when I go to read a file I have it set in the file the information that is relevant to what I am loading.
Example : single - single for single image, sheet for sprite sheet
2 - number of images
char1.png - image 1
char2.png - image 2
Example : sheet
3 - frames across
4 - frames down
char1.png - sprite sheet
Here is the function, the "single" part works perfect it loads the images and I display them, that's fine. The second part of the function "sheet" spits out all the correct information for image positions but half the time it exits with an odd code in the console -10773740940, and if it doesn't exit after I click load it spits out the same exit code if I hit the exit button. Is there something glaringly wrong with my code, or is a bug?? If you want all the source I will throw it up, but this is the problem, if I comment it out everything works fine.
Function LoadSprite() 'Add functionality for spriteSheet tNumImg$ = "" typeImg$ = "" tempIn$ = "" sheetImg$ = "" tWidth = 0 tHeight = 0 nWidth = 0 nHeight = 0 sWidth = 0 sHeight = 0 f = FreeFile
FileOpen(f, "ImageList.txt", TEXT_INPUT) typeImg = ReadLine(f)
If typeImg = "single" And fileLoaded = False Then tNumImg = ReadLine(f) TOTAL_IMG = Val(tNumImg)
For i = 0 To TOTAL_IMG -1 Images$[i] = ReadLine(f)
If IsLoaded[i] = 0 Then IsLoaded[i] = 1 LoadImage(imgID, Images$[i]) ImageSlot[i] = imgID imgID = imgID + 1 End If
GetImageSize(ImageSlot[i], tWidth, tHeight) nWidth = 64 / tWidth nHeight = 64 / tHeight
ImageScaleX[i] = nWidth ImageScaleY[i] = nHeight Next drawImg = True fileLoaded = True End If
'This the problem part of the code!!! ->
If typeImg = "sheet" And fileLoaded = False Then tempIn = ReadLine(f) 'Frames across first, Frames down second fAcross = Val(tempIn)
tempIn = ReadLine(f) fDown = Val(tempIn)
tempIn = ReadLine(f) sheetImg = tempIn
LoadImage(imgID, sheetImg)
GetImageSize(imgID, sWidth, sHeight) sizeX = sWidth / fAcross sizeY = sHeight / fDown modX = 0 'modifier for sheet position modY = 0 TOTAL_IMG = fAcross * fDown
For i = 0 To TOTAL_IMG -1 ImageSheetPosX[i] = modX * sizeX ImageSheetPosY[i] = modY * sizeY
modX = modX + 1 If modX = fAcross Then modX = 0 modY = modY + 1 End If Print ImageSheetPosX[i] Print ImageSheetPosY[i] Next drawSheet = True fileLoaded = True End If FileClose(0)
End Function
Thanks
|
|
|
Post by n00b on Sept 1, 2018 10:30:35 GMT -6
Can you provide the file you are trying to load?
|
|
|
Post by tbird on Sept 1, 2018 10:55:07 GMT -6
Here is the image, it sometimes loads and sometimes just exits....?
|
|
|
Post by n00b on Sept 1, 2018 11:29:11 GMT -6
I had to try to fill in the code you didn't provide so I changed a few things. I think probably the biggest thing I changed was the LoadImage call.
Run this:
fileLoaded = False Dim Images$[20] Dim ImageSlot[20] Dim ImageScaleX[20] Dim ImageScaleY[20] Dim isLoaded[20] Dim imgID Dim ImageSheetPosX[20] Dim ImageSheetPosY[20] Dim TOTAL_IMG Dim sizeX Dim sizeY Function LoadSprite() 'Add functionality for spriteSheet tNumImg$ = "" typeImg$ = "" tempIn$ = "" sheetImg$ = "" tWidth = 0 tHeight = 0 nWidth = 0 nHeight = 0 sWidth = 0 sHeight = 0 f = FreeFile FileOpen(f, "ImageList.txt", TEXT_INPUT) typeImg = ReadLine(f) If typeImg = "single" And fileLoaded = False Then tNumImg = ReadLine(f) TOTAL_IMG = Val(tNumImg) For i = 0 To TOTAL_IMG -1 Images$[i] = ReadLine(f) If IsLoaded[i] = 0 Then IsLoaded[i] = 1 LoadImage(imgID, Images$[i]) ImageSlot[i] = imgID imgID = imgID + 1 End If GetImageSize(ImageSlot[i], tWidth, tHeight) nWidth = 64 / tWidth nHeight = 64 / tHeight ImageScaleX[i] = nWidth ImageScaleY[i] = nHeight Next drawImg = True fileLoaded = True End If
'This the problem part of the code!!! ->
If typeImg = "sheet" And fileLoaded = False Then tempIn = ReadLine(f) 'Frames across first, Frames down second fAcross = Val(tempIn) tempIn = ReadLine(f) fDown = Val(tempIn) tempIn = ReadLine(f) sheetImg = tempIn If OS = "WINDOWS" Then LoadImage(imgID, Dir$ + "\\" + sheetImg) Else LoadImage(imgID, Dir$ + "/" + sheetImg) End If GetImageSize(imgID, sWidth, sHeight) print imgID sizeX = sWidth / fAcross sizeY = sHeight / fDown modX = 0 'modifier for sheet position modY = 0 TOTAL_IMG = fAcross * fDown print TOTAL_IMG For i = 0 To TOTAL_IMG -1 ImageSheetPosX[i] = modX * sizeX ImageSheetPosY[i] = modY * sizeY modX = modX + 1 If modX = fAcross Then modX = 0 modY = modY + 1 End If Print ImageSheetPosX[i] Print ImageSheetPosY[i] Next drawSheet = True fileLoaded = True End If FileClose(0)
End Function WindowOpen(0, "test", WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, 640, 480, 0) CanvasOpen(0, 640, 480, 0, 0, 640, 480, 0) LoadSprite frame = 0 t = timer While Not Key(K_ESCAPE) ClearCanvas if timer - t > 150 then t = timer frame = frame + 1 if frame >= TOTAL_IMG Then frame = 0 end if end if DrawImage_Blit(imgId, 30, 30, ImageSheetPosX[frame], ImageSheetPosY[frame], sizeX, sizeY) Update Wend
|
|
|
Post by tbird on Sept 1, 2018 12:10:54 GMT -6
Hmm ok I will test when I got home.
Thank you.
|
|
|
Post by tbird on Sept 1, 2018 12:46:54 GMT -6
Ok, so the problem was, I was trying to use my LoadSprite() function inside the loop, I did what you did and called it before the main loop and no more issue.....
It seems so simple I spent an hour on that stupid problem lol.
Thank you!
|
|
|
Post by tbird on Sept 2, 2018 9:50:15 GMT -6
Well that wasn't the problem...I finally figured it out....wow I feel dumb I initialized my arrays with a smaller value, so I kept accessing some unknown memory, so I have it back to the original code, and it works fine. I will go find a hole to hide in now
|
|
|
Post by n00b on Sept 2, 2018 11:31:43 GMT -6
I make those mistakes all the time. It usually helps me to create a debug routine that prints the value of every variable and use it where I am encountering a bug.
|
|
|
Post by tbird on Sept 2, 2018 13:34:16 GMT -6
Yes I was printing out values, but as you said do it for all variables, I was only for particular ones....must learn!! I will take the experience and hopefully do something with it.
|
|