Jump to content

loading screen text showing and end of game not at the start


onaid
 Share

Recommended Posts

hi guys , trying to get a simple loading text at the start of my game , but it is drawing text at the end when i hit escape it then draws the text? i am using the context:::draw text after the world create line in main lua here is my main lua..................................

 

--Initialize Steamworks (optional)

Steamworks:Initialize()

 

--Initialize analytics (optional). Create an account at www.gameamalytics.com to get your game keys

--[[if DEBUG==false then

Analytics:SetKeys("GAME_KEY_xxxxxxxxx", "SECRET_KEY_xxxxxxxxx")

Analytics:Enable()

end]]

 

--Set the application title

title="soundscape"

 

--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")))

function App:Start()

 

self.window = Window:Create()

self.context = Context:Create(self.window)

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

self.context:SetFont(font)

font:Release()

return true

end

 

function App:Loop()

 

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

 

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

self.context:Clear()

 

--Draw some centered text on the screen

local text = "Loading"

 

local font = self.context:GetFont()

 

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

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

 

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

y = y - font:GetHeight()/2

 

self.context:SetBlendMode(Blend.Alpha)

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

self.context:DrawText(text,x,y)

self.context:SetBlendMode(Blend.Solid)

 

self.context:Sync()

return true

end

--Load a map

 

local mapfile = System:GetProperty("map","Maps/start.map")

if Map:Load(mapfile)==false then return end

prevmapname = FileSystem:StripAll(changemapname)

 

--Send analytics event

Analytics:SendProgressEvent("Start",prevmapname)

 

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

 

--Pause the clock

Time:Pause()

 

--Pause garbage collection

System:GCSuspend()

 

--Clear all entities

world:Clear()

 

--Send analytics event

Analytics:SendProgressEvent("Complete",prevmapname)

 

--Load the next map

if Map:Load("Maps/"..changemapname..".map")==false then return end

prevmapname = changemapname

 

--Send analytics event

Analytics:SendProgressEvent("Start",prevmapname)

 

--Resume garbage collection

System:GCResume()

 

--Resume the clock

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

 

 

how do i get it to draw text at the start and disappear when game is loaded ?

 

cheers ..

Link to comment
Share on other sites

Add this before both the calls to Map:Load. You can adjust it as desired.

--Draw a loading message
context:SetColor(0,0,0,1)
context:Clear()
context:SetColor(1,1,1,1)
context:SetBlendMode(Blend.Alpha)
context:DrawText("Loading...",0,0)
context:SetBlendMode(Blend.Solid)
context:Sync()

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

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