aldoz Posted July 21, 2016 Share Posted July 21, 2016 Hi again guys, I am trying to put some text on my screen but a basic thing such this seems impossible for me... I can't get text and the only thing I get is NO texts on screen. Tried a bunch of forum examples but nothing! So, I put a sphere on the "terrain demo" and I made a script to let to push it pressing a key. This work fine! But in the same script I add a function to draw some text using App:loop but I am not sure.... I getting nill value error too.. here my code : function Script:UpdatePhysics() if window:KeyDown(Key.F) then self.entity:AddForce(50,0,0,true) end 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 Quote Link to comment Share on other sites More sharing options...
Josh Posted July 21, 2016 Share Posted July 21, 2016 I can't run your example because it isn't a complete script, but try this: self.context:SetColor(1,1,1,1) It might be that your alpha color is set to zero. Also, if you want to center the text use the context width and height, not the window. The window dimensions include the frame and titlebar, which you don't want. 1 Quote 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 More sharing options...
aldoz Posted July 21, 2016 Author Share Posted July 21, 2016 mmm tried but nothing change. I notice that, when I get out from demo, using esc key, I get "Script Error attempt to index field 'window' (a nil value) If I delete the first script line so I get this error in the following code line : Script Error attempt to index field 'context' (a nil value) Damn me when I lost time using Dark Basic Quote Link to comment Share on other sites More sharing options...
aldoz Posted July 21, 2016 Author Share Posted July 21, 2016 Ok I get this working : 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 Using this code inside the ball script, when I push esc key so I read the write! 1 Quote Link to comment Share on other sites More sharing options...
aldoz Posted July 21, 2016 Author Share Posted July 21, 2016 Ok with the following code I can put a text on the center of the screen! So, solved function Script:Start() self.font = Font:Load("Fonts/Ranchers-Regular.ttf",32) if self.font==nil then local context = Context:GetCurrent() self.font = context:GetFont() end end function Script:PostRender(context) context:SetBlendMode(Blend.Alpha) context:SetColor(1,0,0,1) local text local prevfont = context:GetFont() prevfont:AddRef() context:SetFont(self.font) local fh=self.font:GetHeight() local timestring text="Level Complete" context:DrawText(text,(context:GetWidth()-self.font:GetTextWidth(text))/2,(context:GetHeight()-fh)/2-fh*1.5) end 2 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.