Page 1 of 1
LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 8:02 pm
by tutiplain
Hi all,
I am trying to load and display a simple sprite, but the LoadSprite() function always returns 0. Can anyone tell me what I'm doing wrong?
Code: Select all
;init code
InitSprite()
InitKeyboard()
UseJPEGImageDecoder()
UseJPEGImageEncoder()
UseJPEG2000ImageDecoder()
UseJPEG2000ImageEncoder()
;data section, binary includes
;DataSection
; IncludeBinary "stick_figure.JPG"
;EndDataSection
;globals
Global x
Global y
;additional setup, load sprites
OpenScreen(800,600,16,"",#PB_Screen_SmartSynchronization)
stick = LoadSprite(#PB_Any,"stick_figure.JPG")
If stick=0
MessageRequester("Error","Unable to load sprite")
End
EndIf
ExamineKeyboard()
;main loop
While KeyboardInkey()<>Chr(27)
ExamineKeyboard()
StartDrawing(ScreenOutput())
DisplaySprite(stick,x,y)
StopDrawing()
FlipBuffers()
Wend
The file exists in the same directory as the source file. Note: specifying full file path does not work, either.
Thanks for any info.
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 8:10 pm
by Demivec
What value does InitSprite() return?
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 8:21 pm
by tutiplain
It returns 1. Let me download/install DX, and see if it solves the problem.
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 9:05 pm
by Comtois
When you will be able to load your sprite, change your loop like this
Code: Select all
;main loop
While KeyboardInkey()<>Chr(27)
ExamineKeyboard()
DisplaySprite(stick,x,y)
FlipBuffers()
Wend
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 9:30 pm
by tutiplain
Installing DirectX runtime didn't solve it. I also changed my code to use a hard-coded sprite number (0), instead of #PB_Any and letting PB assign one on its own. It still doesn't work. The error reported is "The specified #Sprite is not initialized", and it happens on the call to DrawSprite().
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 9:32 pm
by Comtois
i can test on my pc if you put your sprite on line.
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 9:40 pm
by tutiplain
Hi Comtois,
I made the changes you suggested. By removing the call to ExamineKeyboard() before the While, I got "ExamineKeyboard()" must be called before using this command" when the loop begins. After adding it again, I got "The specified #Sprite is not initialized", on the call to DrawSprite(). Any more suggestions?
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 9:42 pm
by Comtois
try another image.
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 9:45 pm
by Nituvious
Try using and image format .jpeg instead of .JPG
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 9:53 pm
by Comtois
tutiplain wrote:Hi Comtois,
I made the changes you suggested. By removing the call to ExamineKeyboard() before the While, I got "ExamineKeyboard()" must be called before using this command" when the loop begins. After adding it again, I got "The specified #Sprite is not initialized", on the call to DrawSprite(). Any more suggestions?
i just suggest you to remove
StartDrawing(ScreenOutput()) StopDrawing()
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 9:57 pm
by tutiplain
Tried another image. Didn't work either.
Could it have something to do with the PB version I'm using. I am using 4.51, under windows xp professional, SP3. The image is a stick figure drawn with Paint. I will try to upload to my site later, but I suppose any image you create in Paint should have the same problem. I also tried using a .bmp and had the same problem.
Comtois, I did remove the StartDrawing() and StopDrawing() calls. No effect, either.
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 10:16 pm
by Comtois
this code work on my pc , download
PureBasic logo to test.
Code: Select all
;init code
InitSprite()
InitKeyboard()
UsePNGImageDecoder()
;globals
Global x
Global y
;additional setup, load sprites
OpenScreen(800,600,16,"",#PB_Screen_SmartSynchronization)
stick = LoadSprite(#PB_Any,"purebasic_logo.png")
If stick=0
MessageRequester("Error","Unable to load sprite")
End
EndIf
;main loop
Repeat
FlipBuffers()
ClearScreen(0)
ExamineKeyboard()
DisplaySprite(stick,x,y)
Until KeyboardPushed(#PB_Key_Escape)
Re: LoadSprite() not working, please help!
Posted: Wed Jan 26, 2011 11:34 pm
by netmaestro
I've had similar problems using a screen depth of 16. Try 32 for better success.
Re: LoadSprite() not working, please help!
Posted: Thu Jan 27, 2011 1:09 pm
by tutiplain
Hi again, everyone.
Changing to 32-bit depth solved the issue. Also, downgrading to PB 4.41 seems to have made it work using 16-bit depth. Thanks to everyone who replied, and for all the advice.