Splash Screen

Advanced game related topics
Hot Pockets
User
User
Posts: 51
Joined: Mon Jun 01, 2009 3:56 am

Splash Screen

Post by Hot Pockets »

Could someone please show me how to make a splash screen using a bmp image file. The examples show drawing an image but I have a great image I want to use for a 1024 x 768 splash screen.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

If you're wanting a splash screen to fade in against the desktop background before your DX screen opens, a borderless layered window with your bmp as a background brush (or image gadget) would work fine. There should be examples of this on the forums.

Simple demo:

Code: Select all

UseJPEGImageDecoder()
LoadImage(0,#PB_Compiler_Home+"examples\sources\data\r2skin.jpg")

OpenWindow(0,0,0,512,512,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)
hBrush = CreatePatternBrush_(ImageID(0))
SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(WindowID(0),0,1)
HideWindow(0,0)

alpha=0
Repeat
  ev=WindowEvent()
  If ev=#PB_Event_CloseWindow:End:EndIf
  SetLayeredWindowAttributes_(WindowID(0),0,alpha,#LWA_ALPHA)
  alpha+1
  Delay(20)
Until alpha=255 Or GetAsyncKeyState_(#VK_SPACE)&32768

t=ElapsedMilliseconds()
Repeat
  ev=WindowEvent()
  If ev=#PB_Event_CloseWindow:End:EndIf
 Until ElapsedMilliseconds()-t>=2000 Or GetAsyncKeyState_(#VK_SPACE)&32768

CloseWindow(0)
DeleteObject_(hBrush)

; Open screen and go on
Last edited by netmaestro on Mon Jun 01, 2009 4:50 am, edited 1 time in total.
BERESHEIT
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Blankname
Enthusiast
Enthusiast
Posts: 120
Joined: Sun Oct 14, 2012 9:11 am

Re: Splash Screen

Post by Blankname »

netmaestro wrote:If you're wanting a splash screen to fade in against the desktop background before your DX screen opens, a borderless layered window with your bmp as a background brush (or image gadget) would work fine. There should be examples of this on the forums.

Simple demo:

Code: Select all

UseJPEGImageDecoder()
LoadImage(0,#PB_Compiler_Home+"examples\sources\data\r2skin.jpg")

OpenWindow(0,0,0,512,512,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)
hBrush = CreatePatternBrush_(ImageID(0))
SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(WindowID(0),0,1)
HideWindow(0,0)

alpha=0
Repeat
  ev=WindowEvent()
  If ev=#PB_Event_CloseWindow:End:EndIf
  SetLayeredWindowAttributes_(WindowID(0),0,alpha,#LWA_ALPHA)
  alpha+1
  Delay(20)
Until alpha=255 Or GetAsyncKeyState_(#VK_SPACE)&32768

t=ElapsedMilliseconds()
Repeat
  ev=WindowEvent()
  If ev=#PB_Event_CloseWindow:End:EndIf
 Until ElapsedMilliseconds()-t>=2000 Or GetAsyncKeyState_(#VK_SPACE)&32768

CloseWindow(0)
DeleteObject_(hBrush)

; Open screen and go on
Not bad, thanks for example code. Here is a updated version of it.

Code: Select all

LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\PureBasicLogo.bmp")

If OpenWindow(0, 0, 0, 381, 68, "", #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_Invisible)
  SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED | #WS_EX_TOOLWINDOW)
  hBrush = CreatePatternBrush_(ImageID(0))
  SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
  InvalidateRect_(WindowID(0), 0, 1)
  HideWindow(0, 0)
  
  For alpha = 0 To 255
    WindowEvent()
    SetLayeredWindowAttributes_(WindowID(0), 0, alpha, #LWA_ALPHA)
    Delay(5)
  Next
  
  Timer = ElapsedMilliseconds()
  Repeat
    WindowEvent()
    Delay(1)
  Until ElapsedMilliseconds()-Timer >= 3000
  
  CloseWindow(0)
  DeleteObject_(hBrush)
EndIf
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Splash Screen

Post by TI-994A »

Hello guys! Great implementations of splash screens, especially the fader. However, for a simple cross-platform solution, this works too:

Code: Select all

EnableExplicit
InitNetwork()

Enumeration
  #MainWindow
  #splashWindow  
  #splashImage
  #splashPicture
EndEnumeration

Define.i wFlags, iWidth, iHeight, tWidth, displayTime, mainFlag, splashFont, splashText.s

If ReceiveHTTPFile("https://www.dropbox.com/s/9is77u0d7xzhvjy/rainbow.bmp?dl=1",
                   GetTemporaryDirectory() + "splash.bmp")
  If LoadImage(#splashPicture, GetTemporaryDirectory() + "splash.bmp")
    iWidth = ImageWidth(#splashPicture)
    iHeight = ImageHeight(#splashPicture)    
    splashFont = FontID(LoadFont(#PB_Any, "Arial", 9))
    splashText = "Splash Screen Example - Copyright (c) TI-994A"
    StartDrawing(ImageOutput(#splashPicture))      
      DrawingFont(splashFont)
      DrawingMode(#PB_2DDrawing_Transparent)
      tWidth = TextWidth(splashText)
      DrawText((iWidth - tWidth) / 2, iHeight - 30, splashText, #Black)
    StopDrawing()
    wFlags = #PB_Window_BorderLess | #PB_Window_ScreenCentered
    If OpenWindow(#splashWindow, #PB_Any, #PB_Any, iWidth, iHeight, "", wFlags)
      ImageGadget(#splashImage, 0, 0, iWidth, iHeight, ImageID(#splashPicture))
      StickyWindow(#splashWindow, 1)
      displayTime = ElapsedMilliseconds()
      While ElapsedMilliseconds() - displayTime < 5000
        WaitWindowEvent(100) 
        If ElapsedMilliseconds() - displayTime > 3000 And Not mainFlag
          wFlags = #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget
          OpenWindow(#MainWindow, #PB_Any, #PB_Any, 640, 480, "Main Program", wFlags)
          mainFlag = 1
        EndIf
      Wend
      CloseWindow(#splashWindow)
    EndIf
  EndIf
EndIf

If Not mainFlag: End: EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
The InitNetwork() function is only required because the example uses an image from my DropBox folder. You can remove it if you're using your own local image. And remember to add the relevant image decoders (UseJPEGImageDecoder, UsePNGImageDecoder, etc.) if required. Also, the main program window is initialised in the timer loop to simulate a concurrent threaded process. Otherwise, it could just be opened after the splash window closes.
EDITS wrote:18th February 2019: updated download links
Last edited by TI-994A on Mon Feb 18, 2019 5:35 am, edited 2 times in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Splash Screen

Post by Little John »

TI-994A wrote:a simple cross-platform solution
Nice, thank you!
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Splash Screen

Post by em_uk »

Cross platform version doesn't as intended on Win7 x64 PB5.20b5 x86.

The rainbow image is shown immediately and then after the loop the surround window appears.
----

R Tape loading error, 0:1
Post Reply