idrougge |
18 February 2016 17:43 |
Simple corkscrew scroller in Blitz2
1 Attachment(s)
There has been talk in several threads about scrolling techniques, and one which is very promising is the so-called corkscrew scroll. This has been described in depth in depth in http://aminet.net/package/dev/src/ScrollingTrick and some have already investigated its feasibility in Blitz Basic.
Here is a very basic implementation. It scrolls for ten screens using only a bitmap 352 pixels wide and 256+10 pixels high. This exploits the fact that soft scrolling on the Amiga only offsets a starting pointer into a bitplane. Since Blitz's DisplayBitmap command doesn't do any bounds checking (thankfully), it can be incremented beyond the width of the bitmap scrolled, upon which it "wraps around" to the starting position, but one pixel down. So if you allocate an extra pixel in height for your bitmap (for each screenwidth scrollable — in this case ten), the bitmap is offset down, and all you have to do is blit in new background blocks in the currently obscured part of the bitmap (it's two blocks wider than the visible screen), offset one pixel down for each screenwidth scrolled.
Thanks to ReadOnlyCat, MrsBeanBag, Shatterhand, Luman and others for discussing this in depth in previous threads.
Code:
#BORDER=1
.makron
Macro Border
CNIF #BORDER=1
MOVE.w #`1,$dff180
CEND
End Macro
.init
DecodeShapes 0,?font ; Incbinned below
#SCRWIDTH=320
#BLOCKWIDTH=16
#BMWIDTH=#SCRWIDTH+#BLOCKWIDTH+#BLOCKWIDTH
#SCREENS=10
BitMap 0,#BMWIDTH,256+#SCREENS,4
BitMap 1,320,10,1
shapenr=1
Use BitMap 0
For y=0 To 256-16-1 Step 16
For x=0 To (320+16) Step 16
Block shapenr,x,y
Next x
shapenr+1
Next y
BLITZ
For i=0 To 15 : PalRGB 0,i,i,i,i : Next i
PalRGB 0,1,15,15,15
InitCopList 0,44,240,$14,8,16,0 ; lores, 4 bpl, 8 spr, mjukscroll
InitCopList 1,44+240+2,$10,$11,8,2,0 ; lores, 4 bpl, 8 spr, mjukscroll
BLITZ ; Enter Blitz mode
BitMapOutput 1 ; Write debug info on little screen
CreateDisplay 0,1 ; A screen with coplist 0 och 1
DisplayPalette 0,0 ; Use palette for bitmap 0
DisplayPalette 1,0 ; Use palette for bitmap 1
DisplayBitMap 1,1 ; Make debug screen visible
.finscroll
#VBL=1
#SCROLLSPEED=1
xscroll=16 ; Scroll position, increments infinitely
x=0 ; X position for blitting, reset upon each wraparound
yoffset=1 ; Y offset for blitting, incremented for each wraparound
Repeat
VWait #VBL
DisplayBitMap 0,0,xscroll,0
If xscroll MOD #BMWIDTH = 0
!Border{$ff0}
; MouseWait
shapenr+1
EndIf
If x=320+16+16
x=0
yoffset+1
EndIf
Locate 0,0 : Print "Xscroll: ",xscroll," X: ",x," yoffset: ",yoffset
If xscroll MOD #BLOCKWIDTH = 0
!Border{$f00}
; MouseWait
For y=0 To 256-16 Step 16
Block shapenr,x,y+yoffset
;Line x,y+yoffset,x+15,y+yoffset,3
Next y
EndIf
xscroll+#SCROLLSPEED : x+#SCROLLSPEED
Until JoyC(0)=2
End
.font
IncBin "Data:BB2/font.shapes"
Note that this is very rough around the edges. It looks boring, there is debug output, the blitting of blocks isn't spread out in time so it doesn't run smoothly and there is no provision for scrolling in the opposite direction. But it goes to show that horizontal corkscrew scrolling is quite possible in Blitz2.
|