Jump to content

I have no idea whats going on here


epsilonion
 Share

Recommended Posts

Hi guys,

 

I made a menu, loaded in a background file for test purposes and assigned a few menu items

 

Start

Settings

Exit

 

When the program first starts a flag is set to 1 so the menu appears when the program has loaded

up.

 

Then it goes into a while loop, while the flag is = 1, then theirs a if block for the menu items.

 

this is where it gets funny.. I have assigned keys to the menu as well as mouse positions, if the mouse is in location and left button is pressed or the T key is pressed then re size the screen to full screen.

 

It works when you press the T key but when you click it, it re-sizes the screen but does not call the menu draw function again to re-size the menu background and text.

 

its wierd because it works if I don't put the menu draw in its own function but then it will not re-size the background or the menu text because it can not be called from the if bock..

 

I have attached the lua file.

App.rar

Link to comment
Share on other sites

It's a little confusing to follow, but my suggestions would be:

 

1) loadMenu() isn't loading anything. It's drawing your menu. Naming it as such will make it's purpose more obvious (drawMenu())

 

2) You have multiple context:Sync()'s going on. There shouldn't be a need for that. Just leave the updating of the time/world and syncing where it originally is in the default App.lua.

 

3) You might want to look at state's. Most games have higher level states like (Splash Screen, Main Menu, Gameplay, etc). It can help to break your game into these states where each state has it's own Init(), Update(), & Draw() functions. You would do this to separate their duties. Then in your App:Loop() you would determine which state you are currently in and call it's Update() and Draw(). A simple example of this could be:

 

 

App.lua

======

 

function App:Start()
  ...
  -- start out in the main menu state
  self.currentState = "main.menu"
end

function App:MenuUpdate()
  -- this is where you look for key presses and mouse clicks specific to the main menu
end

function App:MenuDraw()
  -- this is where we draw anything related to the menu
end

function App:update()
 --Update the app timing
 Time:Update()

 --Update the world
 self.world:Update()

 -- determine what state we are in
 if self.currentState == "main.menu" then
        self:MenuUpdate()
    elseif self.currentState == "somethingelse" then
    end
end

function App:draw()
   --Render the world
   self.world:Render()

   --Render statistics
   self.context:SetBlendMode(Blend.Alpha)
   if DEBUG then
       self.context:SetColor(1,0,0,1)
       self.context:DrawText("Debug Mode",2,2)
       self.context:SetColor(1,1,1,1)
       self.context:DrawStats(2,22)
       self.context:SetBlendMode(Blend.Solid)
    else
      --Toggle statistics on and off
      if (self.window:KeyHit(Key.F11)) then self.showstats = not self.showstats end
      if self.showstats then
            self.context:SetColor(1,1,1,1)
            self.context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2)
      end
    end

    if self.currentState == "main.menu" then
       self:MenuDraw()
    elseif self.currentState == "somethingelse" then


    --Refresh the screen
    self.context:Sync(true)
end

function App:changeMap()

[size=4]	 --Handle map change
 if changemapname~=nil then

 --Clear all entities
 self.world:Clear()

 --Load the next map
 Time:Pause()
 if Map:Load("Maps/"..changemapname..".map")==false then return false end
	  Time:Resume()

	  changemapname = nil
 end [/size]
end

function App:Loop()
 [size=4]-- If window has been closed or App.game = true then end the program[/size]
 if self.window:Closed() then return false end

 -- break this out into it's own function so it's not cluttering up our main loop
 self:changeMap()

self:update()

self:draw()

[size=4]end[/size]

  • Upvote 2
Link to comment
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.

 Share

×
×
  • Create New...