Core Posted November 26, 2015 Share Posted November 26, 2015 What is the best way to handle multiple fonts? Currently I load new font every cycle before every drawtext... I'm very noob with lua, so could someone post short reference script. Quote Link to comment Share on other sites More sharing options...
Rick Posted November 26, 2015 Share Posted November 26, 2015 You should load fonts on startup because they take time to load. Then you switch to those fonts during runtime which is more instant. 1 Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 26, 2015 Share Posted November 26, 2015 small example: window = Window:Create("font example",0,0,400,300) context = Context:Create(window) world = World:Create() camera = Camera:Create() light = DirectionalLight:Create() light:SetRotation(45,45,0) box = Model:Box() box:SetPosition(0,0,3) box:SetColor(1,0,0,1) lilfont = context:GetFont() bigfont = Font:Load("Fonts/arial.ttf", 48, 1) toggle = 0 while window:KeyDown(Key.Escape)==false do if window:Closed() then break end box:Turn(Time:GetSpeed()*0.5,Time:GetSpeed()*0.5,0) if window:KeyHit(Key.Space) then toggle = 1 - toggle end if toggle==0 then context:SetFont(lilfont) else context:SetFont(bigfont) end Time:Update() world:Update() world:Render() context:SetBlendMode(Blend.Alpha) context:DrawText(string.format("FPS: %.2f",Time:UPS()),0,10) context:DrawText("HIT SPACE",0,80) context:Sync(true) end 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...
Core Posted November 26, 2015 Author Share Posted November 26, 2015 Thank you very much. context:SetFont was the key part I missed. Here is my current progress with Tittle screen: Why tab is not working I don't know, sorry a bit hard to read... function Script:Start() self.Tittle = "Tittle" self.Tittle2 = "Subtittle" self.Menutext1 = "Press ENTER" font1 = Font:Load("Fonts/LCD-N.ttf", 100) font2 = Font:Load("Fonts/arial.ttf", 30) font3 = Font:Load("Fonts/LCD-L.ttf", 30) return true end function Script:UpdateWorld() if window:KeyDown(Key.Enter) then self.component:CallOutputs("Activate") end end function Script:PostRender() self.DisplayEnabled = true if self.DisplayEnabled == true then context:Clear() context:SetFont(font1) local font1 = context:GetFont() local screenwidth = window:GetWidth() local screenheight = window:GetHeight() local x = screenwidth/2 local y = screenheight/2 context:SetBlendMode(Blend.Alpha) context:SetColor(0,0,0) context:DrawRect(0,0,screenwidth,screenheight,0) context:SetColor(1,0,0) local font1_x = (screenwidth - font1:GetTextWidth(self.Tittle))/2 local font1_y = (screenheight - font1:GetHeight())/2 context:DrawText(self.Tittle,font1_x,font1_y-200) context:SetFont(font2) context:SetColor(1,1,1) context:DrawText(self.Tittle2,x+80,y-130) local font3_x = (screenwidth - font3:GetTextWidth(self.Menutext1))/2 local font3_y = (screenheight - font3:GetHeight())/2 context:SetFont(font3) context:DrawText(self.Menutext1,font3_x,font3_y+200) end context:SetBlendMode(Blend.Solid) end I'm just getting a bit frustrated for the lack of documentation... I understand that this is a one big learning experience, but feels that I spend too much time searching from the net and combining different pieces of information in to one just to put up some very basic tittle screen, for example. Every game needs an UI! There should be official tutorial for it! Next step is to learn to load map after pressing enter on tittle screen, and it sounds simple enough, but I'm allready sure it is not that simple... But, sorry for ranting, I love Leadwerks still I'm more angry at myself and my thick head. Quote Link to comment Share on other sites More sharing options...
shadmar Posted November 26, 2015 Share Posted November 26, 2015 Context class is doucumented in the API with examples. But there is not a GUI a gui tutorial I'm afraid. http://www.leadwerks.com/werkspace/page/api-reference/_/context/ Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Core Posted November 27, 2015 Author Share Posted November 27, 2015 Thanks shadmar. I'm aware of the API reference and it is very useful, but examples could be commented so noob like me would know exactly what specific line does. I bought FlowGUi and it is very helpful! Quote 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.