Works with transformed, rotated sprites. Should be apply before zoomsprite though.
[Escape] to quit.
Do not consider code below, See last code posts.
Code: Select all
If InitSprite() = 0 Or InitKeyboard() = 0:MessageRequester("Error", "Can't open the sprite system", 0):End:EndIf
If OpenWindow(0, 0, 0,800,600, "Scroll Sprite", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)=0:MessageRequester("Error", "Can't open windowed screen!", 0):EndIf
If OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0)=0:MessageRequester("Error", "Can't open windowed screen!", 0):EndIf
LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")
Procedure Scroll(sprite.i,StepX.i,StepY.i)
If StartDrawing(SpriteOutput(sprite))
Buffer.i= DrawingBuffer()
Pitch.i= DrawingBufferPitch()
If StepX>0
StepX<<2
*Dest=AllocateMemory(StepX)
For y = 0 To SpriteHeight(sprite)-1
*debut = Buffer+Pitch*y
CopyMemory(*debut,*Dest,StepX)
CopyMemory(*debut+StepX,*debut,pitch-StepX)
CopyMemory(*Dest,*debut+Pitch-StepX,StepX)
Next y
FreeMemory(*dest)
ElseIf StepX<0
StepX=Abs(StepX)
StepX<<2
*Dest=AllocateMemory(StepX)
For y = 0 To SpriteHeight(sprite)-1
*debut = Buffer+Pitch*y
CopyMemory(*debut+pitch-StepX,*Dest,StepX)
CopyMemory(*debut,*debut+StepX,pitch-StepX)
CopyMemory(*Dest,*debut,StepX)
Next y
FreeMemory(*dest)
EndIf
If StepY>0
*Dest=AllocateMemory(pitch*StepY)
*debut = Buffer
CopyMemory(*debut,*Dest,pitch*StepY)
CopyMemory(*debut+pitch*StepY,*debut,pitch*(SpriteHeight(sprite)-StepY))
CopyMemory(*Dest,*debut+pitch*(SpriteHeight(sprite)-StepY),pitch*StepY)
FreeMemory(*dest)
ElseIf StepY<0
StepY=Abs(StepY)
*debut = Buffer
*Dest=AllocateMemory(pitch*StepY)
CopyMemory(*debut+pitch*(SpriteHeight(sprite)-StepY),*Dest,pitch*StepY)
CopyMemory(*debut,*debut+pitch*StepY,pitch*(SpriteHeight(sprite)-StepY))
CopyMemory(*Dest,*debut,pitch*StepY)
FreeMemory(*dest)
EndIf
StopDrawing()
EndIf
EndProcedure
Repeat
WindowEvent()
ExamineKeyboard()
FlipBuffers()
ClearScreen(#Black)
;RotateSprite(0,0.1,#PB_Relative)
If time.d<ElapsedMilliseconds():stepx=Random(4)-2:stepy=Random(4)-2:time=ElapsedMilliseconds()+3000:EndIf
Scroll(0,stepx,stepy)
DisplaySprite(0,ScreenWidth()/2-SpriteWidth(sprite)/2,ScreenHeight()/2)
Until KeyboardPushed(#PB_Key_Escape)