Jump to content

Leadwerks Map loading ->HOW ?


Slastraf
 Share

Recommended Posts

...

function App:SwitchLevel(levelname)

self.world:Clear()

self.world = World:Create()

self.mapFile = name

self.world:Release()

end

...

function App:Loop()

self:ShouldSwitchLevel()

 

--If window has been closed, end the program

if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

 

 

if (self.window:KeyHit(Key.C)) then

self.world:Clear()

self:SwitchLevel("Maps/Level01.map")

 

end

 

 

So I have been working on a new project and it always seemed to be no big deal to load a map but right now I dont know why its not loading at all. When i press c (test) it makes the .exe not respond

http://www.artur-betz.de/sdsd..html here the full App.lua

Link to comment
Share on other sites

There should be a tutorial in the Advanced FPS template if I'm not mistaken.

 

Anyway, there are a few errors with that method so far:

  1. name != levelname, so you are loading a nonexistent string
     
  2. You are creating a world when one already exists. Clear() does not delete the world
     
  3. You are releasing a world when you just made one (if your code made it this far, you would be deleting the most recent one presumably)

 

Here is a cleaned up version that should work (untested though):

function App:SwitchLevel(levelname)
 self.world:Clear()
 self.mapFile = levelname
end
...
function App:Loop()
 self:ShouldSwitchLevel()
 --If window has been closed, end the program
 if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

 if (self.window:KeyHit(Key.C)) then
   self:SwitchLevel("Maps/Level01.map")
 end
end

Link to comment
Share on other sites

Main.lua:

--Initialize Steamworks (optional)
Steamworks:Initialize()

--Set the application title
title="Shapes Alive"

--Create a window
local windowstyle = window.Titlebar
if System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+window.FullScreen end
window=Window:Create(title,0,0,System:GetProperty("screenwidth","1024"),System:GetProperty("screenheight","768"),windowstyle)
window:HideMouse()

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

--Create a world
world=World:Create()
world:SetLightQuality((System:GetProperty("lightquality","1")))

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

while window:KeyDown(Key.Escape)==false do

   --If window has been closed, end the program
   if window:Closed() then break end

   --Handle map change
   if changemapname~=nil then

       --Clear all entities
       world:Clear()

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

       changemapname = nil
   end    

   --Update the app timing
   Time:Update()

   --Update the world
   world:Update()

   --Render the world
   world:Render()

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

   --Refresh the screen
   context:Sync(true)

end

 

Trigger_ChangeMap.lua:

--[[
This script will act as a trigger to change the current map.
Place this at the end of your map to make the player progress
to the next level.
]]--

Script.mapname=""--string "Map Name"

function Script:Start()
   self.enabled=true
end

function Script:Collision(entity, position, normal, speed)
   changemapname=self.mapname
end

function Script:Enable()--in
   if self.enabled==false then
       self.enabled=true
       self:CallOutputs("Enable")
   end
end

function Script:Disable()--in
   if self.enabled then
       self.enabled=false
       self:CallOutputs("Disable")
   end
end

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

You're calling world:Release(), which deletes your world and everything in it!

Oh thanks. I missed that and i am new to lua

Here the story:

after inserting the whole new App.lua i was wondering why it still doesnt work but then

I understood that the next level has to be with the Fps player and not just a camera from the editor..

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