Code archives/Miscellaneous/Game Title Screen using FryGUI
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Game Title Screen with centered buttons that highlight when you mouse-over them, and a text-fade effect. I used FryGUI because #1 I wanted the GUI to be able to run Full-Screen and #2 FryGUI is free. For more info on FryGUI, see this post: http://www.blitzbasic.com/Community/posts.php?topic=65067 The code is fairly simple and straightforward, nothing too fancy... | |||||
' Game Title Screen Demo using BlitzMax (1.42) and FryGUI (0.96) ' by Seth Hopkinson, 04-Jun-2011 ' SuperStrict Import Fry.FryGUI ' Variables Local flag:Int,xx:Int,yy:Int,zz:Int,showev:Int,mooccur:Int Local TitleText:String Global statclr:Int,stattime:Int ' Conditional Compiling for different OS. See Help-->Language-->Advanced Topics-->Conditional Compiling ' ?Win32 SetGraphicsDriver D3D7Max2DDriver() ?MacOS SetGraphicsDriver GLMax2DDriver() ?Linux SetGraphicsDriver GLMax2DDriver() ? ' Set up Application, Graphics, Blend Mode, and FryGUI ' See Help-->Third Party Modules-->fry.frygui ' AppTitle = "FryGUI Game Title Screen Demo" ' 1024,768,0,0 runs it in a Window. 1024,768,32,0 runs it Full Screen. Graphics 1024,768,0,0,GRAPHICS_BACKBUFFER ' Graphics 1024,768,32,0,GRAPHICS_BACKBUFFER fry_SetResolution(1024, 768) fry_SystemCursor(False) SetBlend alphablend 'load in a skin for the GUI fry_LoadSkin("Skin") 'add the fonts to the GUI. Fonts will be referenced by their names. The Font Files need to be in the Skin folder. fry_AddFont("Default", "trebucbd.ttf", 13) fry_AddFont("Large", "trebucbd.ttf", 24) 'fry_AddFont("Large", "comic.ttf", 24) ' create screen and panels Local scrTitleScreen:fry_TScreen = fry_CreateScreen("scrTitleScreen") Local pnlTitleText:fry_TPanel = fry_CreatePanel("pnlTitleText", 0, 0, 1024, 100) Local pnlTitleButtons:fry_TPanel = fry_CreatePanel("pnlTitleButtons", 0, 300, 1024, 300) pnlTitleText.HexColour("301030") pnlTitleButtons.HexColour("103010") scrTitleScreen.AddPanel(pnlTitleText) scrTitleScreen.AddPanel(pnlTitleButtons) ' Create Title Text Label TitleText="The title of the game." Local lblTitleText:fry_TLabel = fry_CreateLabel("xlblTitleText", TitleText, 5, 5, 1014, 90, 1, 1, pnlTitleText) lblTitleText.HexTextColour("808080") 'lblTitleText.SetTextColour(128,128,128) lblTitleText.SetFont("Large") ' Create a few buttons ' Note: Centering = (ScreenWidth/2) - (ObjectWidth/2). ' Screen is 1024 wide. Buttons are 200 wide. (1024/2)-(200/2) = 512-100 = 412. xx=412 yy=15 zz=35 Local btnStart:fry_TButton = fry_CreateButton("xbtnStart", "Start New Game", xx, yy, 200, 20, pnlTitleButtons) yy=yy+zz Local btnLoadGame:fry_TButton = fry_CreateButton("xbtnLoadGame", "Load Game", xx,yy,200,20, pnlTitleButtons) yy=yy+zz Local btnOptions:fry_TButton = fry_CreateButton("xbtnOptions", "Options", xx, yy, 200, 20, pnlTitleButtons) yy=yy+zz Local btnCredits:fry_TButton = fry_CreateButton("xbtnCredits", "Credits", xx, yy, 200, 20, pnlTitleButtons) yy=yy+zz Local btnQuit:fry_TButton = fry_CreateButton("xbtnQuit", "Quit", xx, yy, 200, 20, pnlTitleButtons) ' Create Label in Button Panel yy=yy+(zz*2) Global lblStatus:fry_TLabel = fry_CreateLabel("xlblStatus", "No Buttons Pressed", 5, yy, 1014, 20, 1, 1, pnlTitleButtons) lblStatus.HexTextColour("808080") lblStatus.SetFont("Default") yy=yy+zz Local lblInfo:fry_TLabel = fry_CreateLabel("xlblInfo", "Press F4 to enable Event Logging (IDE Output Tab), F5 to disable (default enabled). ESC to Exit.", 5, yy, 1014, 20, 1, 1, pnlTitleButtons) lblInfo.HexTextColour("808080") lblInfo.SetFont("Default") 'Set the initial screen - failure to do this will crash the GUI fry_SetScreen("scrTitleScreen") SetClsColor 10,10,10 flag=1 showev=1 mooccur=1 While flag=1 'Be friendly to other multi-tasking programs... PollSystem 'Redraw GUI objects Cls fry_Refresh() Flip 'if any MouseOver events occured, reset the buttons (ie: set the button TextColor to its "un-highlighted" state). If mooccur=1 btnStart.HexTextColour("202020") btnLoadGame.HexTextColour("202020") btnOptions.HexTextColour("202020") btnCredits.HexTextColour("202020") btnQuit.HexTextColour("202020") mooccur=0 End If 'Poll all the events generated by the GUI While fry_PollEvent() If showev=1 Print fry_EventText() End If If fry_EventID() = fry_EVENT_MOUSEOVER 'had to look at the FryGUI source code to figure this one out. EventSource = "btnStart:Label" in 'the event Log, instead of the expected "btnStart"... This is because the button's text is actually 'a "Fry_tLabel" Object, with the button as its parent, and the MouseOver comes from the Label... If fry_EventSource() = btnStart.gLabel btnStart.HexTextColour("A030A0") If fry_EventSource() = btnLoadGame.gLabel btnLoadGame.HexTextColour("A030A0") If fry_EventSource() = btnOptions.gLabel btnOptions.HexTextColour("A030A0") If fry_EventSource() = btnCredits.gLabel btnCredits.HexTextColour("A030A0") If fry_EventSource() = btnQuit.gLabel btnQuit.HexTextColour("A030A0") mooccur=1 End If If fry_EventID() = fry_EVENT_GADGETACTION 'when you click on a button, the EventSource is the button, as expected. If fry_EventSource() = btnStart btnStart.HexTextColour("606020") setStatus "Start Clicked" End If If fry_EventSource() = btnLoadGame btnLoadGame.HexTextColour("606020") setStatus "Load Game Clicked" End If If fry_EventSource() = btnOptions btnOptions.HexTextColour("606020") setStatus "Options Clicked" End If If fry_EventSource() = btnCredits btnCredits.HexTextColour("606020") setStatus "Credits Clicked" End If If fry_EventSource() = btnQuit btnQuit.HexTextColour("606020") setStatus "Quit Clicked" End If End If Wend If KeyHit(KEY_ESCAPE) flag=0 If KeyHit(KEY_F1) lblTitleText.SetText("F1 will not help you this time!") setStatus "Like, F1 was pressed, or something..." End If If KeyHit(KEY_F2) lblTitleText.SetText("Are we having fun yet?") setStatus "Its very easy to press the F2 key." End If If KeyHit(KEY_F3) lblTitleText.SetText(TitleText) setStatus "Title set to Default" End If If KeyHit(KEY_F4) showev=1 setStatus "Event Logging ON" End If If KeyHit(KEY_F5) showev=0 setStatus "Event Logging OFF" End If updateStatus Wend Function setStatus (txt:String) statclr=224 lblStatus.SetTextColour(statclr,statclr,statclr) lblStatus.SetText(txt) stattime=MilliSecs() End Function Function updateStatus() If statclr>0 Then If statclr<20 Then statclr=0 lblStatus.HexTextColour("808080") lblStatus.SetText("No Buttons Pressed") Else If (MilliSecs()-stattime)>3 statclr=statclr-1 stattime=MilliSecs() lblStatus.SetTextColour(statclr,statclr,statclr) End If End If End If End Function |
Comments
None.
Code Archives Forum