Page 1 of 1

Help with Sprites

Posted: Sat Dec 10, 2022 1:21 am
by itzybitzyspider
Hi guys,

Trying to do a simple load sprite and display process. The image is shown, then it flickers and disappears. I'm sure it has to do with the FlipBuffers() but I can't seem to figure it out.

Code: Select all


InitMouse(#PB_Mouse_Locked)
InitSprite()

ExamineDesktops()
Height.l = DesktopHeight(0)
Width.l = DesktopWidth(0)

Debug(Height)
Debug(Width)
OpenScreen(Width, Height, DesktopDepth(0), "Test")


Dim SpriteList.l(100)
Global SpriteCount.l = 1
Procedure RenderFrame()
  Global SpriteCount
  Static x, y
  
  ClearScreen(RGB(0, 0, 0))
  
  If ExamineMouse()
    If MouseButton(#PB_MouseButton_Left)
      Debug "Left button " + Str(SpriteCount)
      ZoomSprite(SpriteCount, 200, 200)
      SpriteX = MouseX()-SpriteWidth(SpriteCount)/2
      SpriteY = MouseY()-SpriteHeight(SpriteCount)/2
      Debug SpriteX
      Debug SpriteY
      DisplaySprite(SpriteCount, SpriteX, SpriteY)
      SpriteCount = SpriteCount+1
      If SpriteCount > 3 
        SpriteCount = 1
      EndIf
      
      Debug "Next " + Str(SpriteCount)
      
    EndIf
    
    If MouseButton(#PB_MouseButton_Right)
      Debug "Right button"
    EndIf
    
    If MouseButton(#PB_MouseButton_Middle)
      Debug "Middle button"
    EndIf
    
    WheelDelta = MouseWheel()
    If WheelDelta
      Debug "Mouse wheel: " + WheelDelta
    EndIf
  Else
    Debug "Cannot"
  EndIf
  
  FlipBuffers()
  ;// continue the rendering
EndProcedure

; Register the loading event before calling any resource load command
BindEvent(#PB_Event_RenderFrame, @RenderFrame())


LoadSprite(1, "Data/1.jpg")
LoadSprite(2, "Data/2.jpg")
LoadSprite(3, "Data/3.jpg")

FlipBuffers()
Any help is much appreciated.

Re: Help with Sprites

Posted: Sat Dec 10, 2022 1:37 am
by Paul
Just look at the "Sprite.sb" example in the Help file to see the proper way to set everything up.

Re: Help with Sprites

Posted: Sat Dec 10, 2022 11:04 pm
by itzybitzyspider
Worked it out.

I was missing a continuous loop of a DisplaySprite() before the FlipBuffers()

I'm getting it now.