It is currently Fri May 24, 2013 9:28 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 8:02 pm 
Offline
User
User

Joined: Wed Jun 30, 2010 3:00 am
Posts: 43
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:
;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.


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 8:10 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 2401
Location: Utah, USA
What value does InitSprite() return?

_________________
Image


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 8:21 pm 
Offline
User
User

Joined: Wed Jun 30, 2010 3:00 am
Posts: 43
It returns 1. Let me download/install DX, and see if it solves the problem.


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 9:05 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1113
Location: Doubs - France
When you will be able to load your sprite, change your loop like this

Code:
;main loop
While KeyboardInkey()<>Chr(27)
  ExamineKeyboard()

  DisplaySprite(stick,x,y)

  FlipBuffers()
Wend

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 9:30 pm 
Offline
User
User

Joined: Wed Jun 30, 2010 3:00 am
Posts: 43
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().


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 9:32 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1113
Location: Doubs - France
i can test on my pc if you put your sprite on line.

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 9:40 pm 
Offline
User
User

Joined: Wed Jun 30, 2010 3:00 am
Posts: 43
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?


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 9:42 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1113
Location: Doubs - France
try another image.

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 9:45 pm 
Offline
Addict
Addict

Joined: Sat Jul 11, 2009 4:57 am
Posts: 878
Location: United States
Try using and image format .jpeg instead of .JPG

_________________
▓▓▓▓▓▒▒▒▒▒░░░░░


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 9:53 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1113
Location: Doubs - France
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()

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 9:57 pm 
Offline
User
User

Joined: Wed Jun 30, 2010 3:00 am
Posts: 43
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.


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 10:16 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1113
Location: Doubs - France
this code work on my pc , download PureBasic logo to test.

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

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Wed Jan 26, 2011 11:34 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 6465
I've had similar problems using a screen depth of 16. Try 32 for better success.

_________________
Veni, vidi, vici.


Top
 Profile  
 
 Post subject: Re: LoadSprite() not working, please help!
PostPosted: Thu Jan 27, 2011 1:09 pm 
Offline
User
User

Joined: Wed Jun 30, 2010 3:00 am
Posts: 43
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye