Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Help with start-menu


Recommended Posts

This is my start up including splash screen:

 

When the game first loads it goes straight into a splash screen with a disclaimer of pre alpha development and a a little advert saying powered by LEADWERKS Game Engine.

 

The menu is just a basic menu for now until I code for the mouse to interact with the menu, you just use the keyboard to select a menu item.

 

It is not finished and gives me basic function of a menu etc, I have to tidy it up but it was 4am when I did this.. biggrin.png

 

 

Splash Screen:

 

Under the App:start Function

 

--Load a spash screen texture

self.splash = Texture:Load("Images/splash.tex")

 

--Set a flag so it does not run the splash screen everytime it loops

StartUp = 1

 

Under the function App:Loop()

 

-- load a splash screen before starting the game

-- If the startUp flag is grater or equal to 1 then load the splash screen

-- so if it is not greater or equal to 1 then skip past it

 

if startUp >= 1 then

self.context:SetColor(0,0,0)

self.context:Clear() -- Clear the context

self.context:SetColor(1,1,1)

self.context:DrawImage(self.splash,0,0) --Draw the splash screen

self.context:Sync(true) -- Sync so it loads the screen

 

Time:Delay(10000) -- Time delay of 10 sec's while the splash is displayed

-- startUp = 0 -- set the startUp flag to 0 so the splash screen does not

-- display on the next pass in the loop.

 

end -- end the if statement

 

 

Next I put the basic's in for the main menu

 

Basic Menu:

 

 

 

function App:Start()

 

--Set menu flag so the menu comes up when game is first loaded
self.menuFlag = 1


--Load a texture
self.texture = Texture:Load("Images/menuBG.tex")

--set the font and text size for the menu
local font = Font:Load("Fonts/Arial.ttf",24)
self.context:SetFont(font)
font:Release()

 

 

 

function App:Loop()

 

if self.window:Closed() then return false end --If window has been closed, end the program


if self.window:KeyDown(Key.Escape) or self.menuFlag >= 1 then --If the escape key is pressed then display the menu
self.menuFlag = 1

Time:Pause() --pause the game

self.context:SetColor(0,0,0) --display the texture file for the background image
self.context:Clear()
self.context:SetColor(1,1,1)
self.context:DrawImage(self.texture,0,0)

self.context:SetColor(0,0,0) --reset the context colour to black and clear the contect
-- self.context:Clear()

--Draw some on the screen
local text = "Press S -> Start"
local text1 = "Press T -> Settings"
local text2 = "Press X -> Exit"

local font = self.context:GetFont() --get the font that was set above


local x = self.window:GetWidth()/4 --get the window height and width
local y = self.window:GetHeight()/3 -- and set it up for drawing the text

x = x - font:GetTextWidth(text)/2 -- get the text width, height and divide
y = y - font:GetHeight()/2 -- it by 2

self.context:SetBlendMode(Blend.Alpha)
self.context:SetColor(1,1,1)
self.context:DrawText(text,x,y)
self.context:DrawText(text1,x,y +40)
self.context:DrawText(text2,x,y + 80)
self.context:SetBlendMode(Blend.Solid) -- reset blend -- mode

self.context:Sync(true)

self.window:ShowMouse() --show mouse


while self.menuFlag >= 1 do --while loop for the menu selection

if self.window:KeyDown(Key.S) then
self.menuFlag = 0
self.window:HideMouse()

Time:Resume()
Time:Update()
end

if self.window:KeyDown(Key.T) then
self.window:Maximize() --Maximize the window

end

if self.window:KeyDown(Key.X) then

return false
end


end


end

Link to post
Share on other sites

OK got it.... Menu with mouse position and click on the word Start game or press the S key:

 

 

function App:Start()

 

--Set menu flag so the menu comes up when game is first loaded

self.menuFlag = 1

 

 

--Load a texture

self.texture = Texture:Load("Images/menuBG.tex")

 

--set the font and text size for the menu

local font = Font:Load("Fonts/Arial.ttf",24)

self.context:SetFont(font)

font:Release()

 

function App:Loop()

 

---If the escape key is pressed then display the menu

if self.window:KeyDown(Key.Escape) or self.menuFlag >= 1 then

self.menuFlag = 1

 

--pause the game??

Time:Pause()

 

--display the texture file for the background image

self.context:SetColor(0,0,0)

self.context:Clear()

self.context:SetColor(1,1,1)

--self.context:DrawImage(self.texture,0,0)

 

--reset the context colour to black and clear the contect

self.context:SetColor(0,0,0)

-- self.context:Clear()

 

--Draw some centered text on the screen

local text = "Press S -> Start"

local text1 = "Press T -> Settings"

local text2 = "Press X -> Exit"

 

--get the font that was set above

local font = self.context:GetFont()

 

--get the window height and width to find where you want the text

local x = self.window:GetWidth() /3

local y = self.window:GetHeight() /4

 

--get the text width, height and devide it by 2

tx = x - font:GetTextWidth(text)/2

ty = y - font:GetHeight()

 

self.context:SetBlendMode(Blend.Alpha)

self.context:SetColor(1,1,1)

self.context:DrawText(text,tx,ty)

self.context:DrawText(text1,tx,ty +40)

self.context:DrawText(text2,tx,ty + 80)

 

--reset blend mode

self.context:SetBlendMode(Blend.Solid)

 

self.context:Sync(true)

 

--while loop for the menu selection

while self.menuFlag >= 1 do

 

-- returns teh x y position of the mouse cursor

local mousePos = App.window:GetMousePosition()

 

-- Show the mouse cursor

self.window:ShowMouse()

 

if mousePos.x > tx and mousePos.x < (tx + ty / 2) and mousePos.y > ty and mousePos.y < y and self.window:MouseDown(Key.LButton) or self.window:KeyDown(Key.S) then

 

self.menuFlag = 0

self.window:HideMouse()

Time:Resume()

Time:Update()

 

 

elseif mousePos.x > tx and mousePos.x < (tx + ty +40 / 2) and mousePos.y > (ty + 40) and mousePos.y < (y + 40) and self.window:MouseDown(Key.LButton) or self.window:KeyDown(Key.T) then

 

--Maximize the window

self.window:Maximize()

 

 

elseif mousePos.x > tx and mousePos.x < (tx + ty +80 / 2) and mousePos.y > (ty + 80) and mousePos.y < (y + 80) and self.window:MouseDown(Key.LButton) or self.window:KeyDown(Key.X) then

 

return false

 

end

 

end

 

 

end

 

Hope this helps some of you... :D

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...