Help with Sprites

Just starting out? Need help? Post your questions and find answers here.
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Help with Sprites

Post 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.
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: Help with Sprites

Post by Paul »

Just look at the "Sprite.sb" example in the Help file to see the proper way to set everything up.
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Re: Help with Sprites

Post by itzybitzyspider »

Worked it out.

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

I'm getting it now.
Post Reply