DisplaySprite only displays empty white blocks.

Just starting out? Need help? Post your questions and find answers here.
User avatar
KilljoyHeathen
User
User
Posts: 13
Joined: Fri Feb 14, 2014 10:56 pm
Location: Ab, Canada

DisplaySprite only displays empty white blocks.

Post by KilljoyHeathen »

I was just testing out code speed with images and sprites. The code with the images works fine, when I change it to sprites all I get is white blocks. I am assuming it's a fail on my part not a bug.

With Image:

Code: Select all

InitSprite()
InitKeyboard()
UsePNGImageDecoder()

MyImage = LoadImage(#PB_Any, "./Media/Devil.png")
OpenScreen(800,600,32,"Something...",#PB_Screen_SmartSynchronization)

X.w = 0
Y.w = 0
ClearScreen(RGB(0,0,0))
For c = 1 To 1000
  X = Random(798) + 1
  Y = Random(598) + 1
StartDrawing(ScreenOutput())
DrawImage(ImageID(MyImage),X,Y)
StopDrawing()
FlipBuffers()
Next
Delay(1000)
End
With Sprite:

Code: Select all

InitSprite()
InitKeyboard()
UsePNGImageDecoder()

;MySprite = LoadSprite(#PB_Any,"./Media/Devil.png")
LoadSprite(0,"./Media/Devil.png")
OpenScreen(800,600,32,"Something...",#PB_Screen_SmartSynchronization)

X.w = 0
Y.w = 0
ClearScreen(RGB(0,0,0))
For c = 1 To 1000
  X = Random(798) + 1
  Y = Random(598) + 1
DisplaySprite(SpriteID(0),X,Y)
FlipBuffers()
Next
Delay(1000)
End
Also if I uncomment out the **;MySprite = LoadSprite(#PB_Any,"./Media/Devil.png")** and use this instead and switch the SpriteID(0) to SpriteID(MySprite) It keeps saying sprite un-initialised.

**INFO: I am running a Linux box.
“ It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: DisplaySprite only displays empty white blocks.

Post by netmaestro »

First thing I see off the bat is you're using SpriteID with DisplaySprite. DisplaySprite expects the #sprite, not the ID. You're doing DrawImage ok as it does expect the ImageID.
BERESHEIT
User avatar
KilljoyHeathen
User
User
Posts: 13
Joined: Fri Feb 14, 2014 10:56 pm
Location: Ab, Canada

Re: DisplaySprite only displays empty white blocks.

Post by KilljoyHeathen »

If I change it to:

Code: Select all

InitSprite()
InitKeyboard()
UsePNGImageDecoder()

MySprite = LoadSprite(#PB_Any,"./Media/Devil.png")
;LoadSprite(0,"./Media/Devil.png")
OpenScreen(800,600,32,"Something...",#PB_Screen_SmartSynchronization)

X.w = 0
Y.w = 0
ClearScreen(RGB(0,0,0))
For c = 1 To 1000
  X = Random(798) + 1
  Y = Random(598) + 1
DisplaySprite(MySprite,X,Y)
FlipBuffers()
Next
Delay(1000)
End
Still says not initialised. I am confused because it works in another program.
Thank you for the response, will continue reading.
“ It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: DisplaySprite only displays empty white blocks.

Post by netmaestro »

LoadSprite won't work if placed before OpenScreen. Sprite operations all need a viable screen to be open.
BERESHEIT
User avatar
KilljoyHeathen
User
User
Posts: 13
Joined: Fri Feb 14, 2014 10:56 pm
Location: Ab, Canada

Re: DisplaySprite only displays empty white blocks.

Post by KilljoyHeathen »

Ah....yes I just finished reading that in the help file :oops:

Thank you for the quick response.
“ It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas
Post Reply