Jump to content

Tutorial : Lua map changing


YouGroove
 Share

Recommended Posts


--This function will be called once when the program starts



function App:Start()

--Set the application title
self.title="luaTest8"

--Create a window
self.window=Window:Create(self.title)
self.window:HideMouse()

--Create the graphics context
self.context=Context:Create(self.window,0)
if self.context==nil then return false end

--Create a world
self.world=World:Create()

--Load a map
local mapfile = System:GetProperty("map","Maps/map2.map")
if Map:Load(mapfile)==false then return false end

return true
end

--This is our main program loop and will be called continuously until the program ends
function App:Loop()

if self.window:KeyDown(Key.B) then
App.world = World:Create()
local mapfile = "Maps/map1.map"
Map:Load(mapfile)
end


if self.window:KeyDown(Key.V) then
App.world = World:Create()
local mapfile = "Maps/map2.map"
Map:Load(mapfile)
end


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

--Update the app timing
Time:Update()

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

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

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

--Returning true tells the main program to keep looping
return true
end

 

A strange point i didn't got it work first time ?

I got map loading that worked one time only, chaning map, always re opened the same ?

So in the editor i opened and closed the two maps to check them , and Lua code worked prefectly.

Perhaps my PC ? Visual Studio open behind ? Some memory problem ?

Anyway that code above works prefectly in Lua smile.png

Stop toying and make games

Link to comment
Share on other sites

  • 2 months later...

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...