Main Menu

Custom Scroll Image

Started by kevin, September 20, 2005, 09:57:53 PM

Previous topic - Next topic

kevin

 While updating the ScrollImage command in PlayBASIC V1.089 (which is about 5* faster than PB1.088), I thought i'd show a a simple way you can further improve the speed if you need.     The code bellow gains a further 7/8 fps (on a duron 800, gf2 mx 200)..    



PlayBASIC Code: [Select]
   LoadImage "Your_IMage_Here.jpg",1
CopyImage 1,2


; Set the X and Y Scrolling rates
ScrollX=1
ScrollY=2

Do
Cls 0
print "Scroll Image"
print "Fps:"+str$(fps())

ScrollImage 1,-ScrollX,-ScrollY

Scroll_Image_fast(2,ScrollX,ScrollY)


; Get the Displays Center coord
cx=getscreenwidth()/2
cy=(getscreenHeight()/2)

ihx=GetImageWidth(1)/2
ihy=GetImageHeight(1)/2

Radius=200

x#=cosnewvalue(cx,angle,radius)
y#=Sinnewvalue(cy,angle,radius)

DrawImage 1,x#-ihx,y#-ihy,0

x#=cosnewvalue(cx,angle+180,radius)
y#=Sinnewvalue(cy,angle+180,radius)

DrawImage 2,x#-ihx,y#-ihy,0

angle=wrapangle(angle,1)

dot cx,cy

; Display the screen and wait for a key press
Sync
loop



; ------------------------------------------------------------------------
; >> Custom Scroll Image (Faster) <<
; ------------------------------------------------------------------------
;
; This function can actually be faster than the native ScrollImage
; Command. This is possible as the function uses a second temp image
; to help with cache the scroll/wrap image data. But rather than
; create/destory this temp image constantly. It Simply caches it forever.
;
; This can lead to errors if the image you wish to scroll changes size,
; or you try and scroll a selection of different images using this function.
;
; ------------------------------------------------------------------------

Function Scroll_Image_Fast(ThisImage,ScrollX,ScrollY)
Static TempImage
oldsurface=getsurface()

W=GetImageWidth(thisimage)
h=GetImageHeight(thisimage)

ScrollX=mod(ScrollX,w)
ScrollY=mod(ScrollY,h)

RenderToImage ThisImage

if TempIMage=0
TempImage=Getfreeimage()
CopyImage ThisImage,TempImage
else
GetImage TempImage,0,0,w,h
endif

TileImage TempIMage,ScrollX,ScrollY,0
RenderToImage oldsurface

EndFunction







BlinkOk

hehe! (640x480 image)
scroll image=5fps
scroll image fast=625fps