Page 1 of 1

DisplaySprite only displays empty white blocks.

Posted: Sat Feb 15, 2014 9:18 pm
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.

Re: DisplaySprite only displays empty white blocks.

Posted: Sat Feb 15, 2014 9:33 pm
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.

Re: DisplaySprite only displays empty white blocks.

Posted: Sat Feb 15, 2014 9:42 pm
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.

Re: DisplaySprite only displays empty white blocks.

Posted: Sat Feb 15, 2014 9:48 pm
by netmaestro
LoadSprite won't work if placed before OpenScreen. Sprite operations all need a viable screen to be open.

Re: DisplaySprite only displays empty white blocks.

Posted: Sun Feb 16, 2014 1:10 am
by KilljoyHeathen
Ah....yes I just finished reading that in the help file :oops:

Thank you for the quick response.