Display a Loading Screen while loading image media

Started by kevin, June 13, 2008, 12:15:51 PM

Previous topic - Next topic

kevin

Display a Loading Screen while loading image media


This little bit of sample code demonstrates how you might display a loading screen, while your game loads the actual media in the background.

Note: The media is not supplied.. that's your little challenge :)



PlayBASIC Code: [Select]
  LoadingScreenImage=loadNewImage("c:/loadingscreen.jpg")

; make sure we're rendering to the screen
rendertoscreen

; clear it
Cls rgb(0,0,0)


; calc the centered X and Y coords for where to display this image
cx=GetScreenWidth()/2-(GetImageWidth(LoadingScreenImage)/2)
cy=GetScreenHeight()/2-(GetImageHeight(LoadingScreenImage)/2)

; draw this image to screens back buffer.
DrawImage LoadingScreenImage,cx,cy,false

; flip the screen back buffer to the front. So it's now visible. You could delete the LoadingScreenImage now if you wanted.
Sync

; Create Array to the hold the images we're loading.
Dim MyImages(10)

; Run through and load the images
For lp=1 to 10

; Build the filename of this image
ImageFileName$="image"+str$(lp)+".jpg"

; check if this file actually exists, Before trying to load it
if FileExist(imageFilename$)=true

; Load the image
MyImages(lp)=Loadnewimage(ImageFilename$)
else
; Error occurred
#print "Error Loading Image:"+ImageFilename$+" File not Found"
endif
next

; render message to the screens back buffer
Print "Loading Complete"

; Flip the screens back buffer to the front so the user can see it.
Sync
WaitKey
end