oldskool fx - slide

Share your advanced PureBasic knowledge/code with the community.
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

oldskool fx - slide

Post by Fenix »

Hi!

have fun...

Code: Select all

; SLIDE
; -----
;
; oldskool fx
;
; 29.06.2003
;
; coding: Fenix


#WIDTH = 1024
#HEIGHT = 768

#FALSE = 0

#TOP2BOTTOM = 1                                                   ; used as parameter for the fx-procedures
#BOTTOM2TOP = 2


Procedure SlideIn(lType.l)                              ; lType selects fx
; if Fred includes variable steps to for/next, we could do this in one loop
; Hi Fred ;)

   Select lType
      Case #TOP2BOTTOM
         lStartY.l = 0
         lEndY.l = #HEIGHT
         For lCounter.l = lStartY To lEndY                              ; slide draws the pic line by line 
            FlipBuffers()                                                ; and takes the actual line to draw to the rest of the screen
            ClipSprite(1, 0, lCounter, #WIDTH, 1)
            For lCounterY.l = lCounter To lEndY                         ; loop from actual Y position to the bottom of the screen
               DisplaySprite(1, 0, lCounterY)
            Next
         Next
      Case #BOTTOM2TOP
         lStartY.l = #HEIGHT
         lEndY.l = 0
         For lCounter.l = lStartY To lEndY Step -1                      ; slide draws the pic line by line 
            FlipBuffers()                                                ; and takes the actual to draw to the rest of the screen
            ClipSprite(1, 0, lCounter, #WIDTH, 1)
            For lCounterY.l = lCounter To lEndY Step -1                 ; loop from actual Y position to the top of the screen
               DisplaySprite(1, 0, lCounterY)
            Next
         Next
   EndSelect    
EndProcedure

Procedure SlideOut(lType.l)
   Select lType
      Case #TOP2BOTTOM
         lStartY.l = 0
         lEndY.l = #HEIGHT
         For lCounter.l = lStartY To lEndY                              ; from top to bottom
            FlipBuffers()
            GrabSprite(2, 0, lCounter, #WIDTH, 1)                        ; grab the line from screen
            For lCounterY.l = lCounter To 0 Step -1                     ; go from actual position up to the start of the screen
               DisplaySprite(2, 0, lCounterY)
            Next
         Next
      Case #BOTTOM2TOP
         lStartY.l = #HEIGHT
         lEndY.l = 0
         For lCounter.l = lStartY To lEndY Step -1                      ; from bottom to top
            FlipBuffers()
            GrabSprite(2, 0, lCounter, #WIDTH, 1)
            For lCounterY.l = lCounter To lStartY                       ; go from actual position down to the end of the screen
               DisplaySprite(2, 0, lCounterY)
            Next
         Next
   EndSelect
   ClearScreen(0, 0, 0)
   FlipBuffers()         
EndProcedure




MAIN:
UseJPEGImageDecoder()                                                            ; or any other imagedecoder, depending on your imageformat

If InitSprite() = #FALSE                                                         ; needed for our fx
   MessageRequester("ERROR", "InitSprite() failed", #PB_MessageRequester_Ok)
   End
EndIf
OpenWindow(1,0,0,#WIDTH,#HEIGHT,#PB_Window_BorderLess, "oldskool fc")
If OpenWindowedScreen(WindowID(), 0, 0, #WIDTH, #HEIGHT, 0, 0, 0) = #FALSE       ;OpenScreen(#WIDTH, #HEIGHT, 32, "oldskool fx") = #FALSE
   MessageRequester("ERROR", "OpenScreen() failed", #PB_MessageRequester_Ok)
   End
EndIf
If CatchSprite(1, ?image) = #FALSE                                               ; get our image as sprite
   MessageRequester("ERROR", "CatchSprite() failed", #PB_MessageRequester_Ok)     ; if failed -> end
   End
EndIf
 
SlideIn(#TOP2BOTTOM)
SlideOut(#TOP2BOTTOM)

FreeSprite(1)
FreeSprite(2)
CloseScreen()
End


image:
IncludeBinary "caprice15.jpg"                                  ; place your image filename here
imageEnd:

Fenix