zack57 Posted February 3, 2017 Share Posted February 3, 2017 I am new to Lua, I am trying to learn Lua but I can's seem to get the text to show on the screen. Josh send me this link http://www.leadwerks.com/werkspace/page/api-reference/_/context/contextdrawtext-r731 . I have tried to put it in main.lua, tried to create text.lua, I tried to put it in a child of the player as a pivot but nothing shows up. I am trying to learn lua show I need to see the test to know I did it if you know what I mean? Quote ----------------------------------------------------------- Building Game is easier with LeadWerks ! ----------------------------------------------------------- NO to Windows 8 and 10 no way I am going to use them at all!!!! Link to comment Share on other sites More sharing options...
Genebris Posted February 3, 2017 Share Posted February 3, 2017 You should do it in Script:PostRender function, look how default player interface is drawn. Quote Link to comment Share on other sites More sharing options...
zack57 Posted February 3, 2017 Author Share Posted February 3, 2017 I did put this in a text.lua and the put the pivot for the text.lua and put the pivot as a child of the fpsplayer. The in the text.lua I see Script: PostRender I hope this is what you mean? -This function will be called after the world is rendered, before the screen is refreshed. --Use this to perform any 2D drawing you want the entity to display. function Script:PostRender(context) 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 = "Leadwerks" 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 end Quote ----------------------------------------------------------- Building Game is easier with LeadWerks ! ----------------------------------------------------------- NO to Windows 8 and 10 no way I am going to use them at all!!!! Link to comment Share on other sites More sharing options...
extenz Posted February 3, 2017 Share Posted February 3, 2017 function Script:PostRender(context) context:SetBlendMode(Blend.Alpha) context:DrawText("Leadwerks", 20, 20) end That's pretty much all you need Quote Link to comment Share on other sites More sharing options...
zack57 Posted February 3, 2017 Author Share Posted February 3, 2017 I must be missing something I did try that extenz but I can't seem to see anything. when I run it the frist time I got an error then I run it again and I got no error. Quote ----------------------------------------------------------- Building Game is easier with LeadWerks ! ----------------------------------------------------------- NO to Windows 8 and 10 no way I am going to use them at all!!!! Link to comment Share on other sites More sharing options...
macklebee Posted February 3, 2017 Share Posted February 3, 2017 Why do you have the App:Start() and App:Loop() functions inside your Script:PostRender() function? The App functions and App.lua script are deprecated but can still be used as your main script. I personally prefer just using the Main.lua script as it is more straight forward to use. The Script:PostRender() is to be used in an entity script not the main program script. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
zack57 Posted February 4, 2017 Author Share Posted February 4, 2017 Ok I tryed that as well no text comes on the sceen? main.lua 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 = "Leadwerks" 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 --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="Training_For_Life" --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 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 Quote ----------------------------------------------------------- Building Game is easier with LeadWerks ! ----------------------------------------------------------- NO to Windows 8 and 10 no way I am going to use them at all!!!! Link to comment Share on other sites More sharing options...
Thirsty Panther Posted February 4, 2017 Share Posted February 4, 2017 Here is a simple map with a camera, a box, a light and a pivot. The pivot has a script attached called "Text on Screen". This script will put the text on the screen for you without having to worry about the Main.lua script. Map Quote Link to comment Share on other sites More sharing options...
Genebris Posted February 4, 2017 Share Posted February 4, 2017 You didn't include the script. zack57, use default scripts, they have all examples you need. Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted February 5, 2017 Share Posted February 5, 2017 Text On Screen Lua. Attach this script to the pivot in the map above. Quote Link to comment Share on other sites More sharing options...
zack57 Posted February 5, 2017 Author Share Posted February 5, 2017 Thanks for all the help guys! Quote ----------------------------------------------------------- Building Game is easier with LeadWerks ! ----------------------------------------------------------- NO to Windows 8 and 10 no way I am going to use them at all!!!! Link to comment Share on other sites More sharing options...
Recommended Posts
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.