GTkoi Posted September 23, 2019 Posted September 23, 2019 Hello, I would like to know how to put a timer at the top of the screen, when we start our game. Otherwise thank you very much for the previous answers, it helped me a lot ! Quote
havenphillip Posted September 24, 2019 Posted September 24, 2019 Script.font = "" -- path "Font" -- use TrueType font file Script.pos = Vec2(0,30) -- Vec2 "Position" Script.size = 15 -- float "Size" Script.color = Vec4(1,1,0,1) -- color "Color" Script.offset = 20 -- int "Offset" -- make larger if numbers get cut off function Script:Start() self.font = Font:Load(self.font,self.size) if self.font == nil then Debug:Error("Select a font") end end function Script:PostRender(context) defaultFont = context:GetFont() r = self.size + self.offset w = self.pos.x + window:GetWidth()/2 - self.offset h = self.pos.y --time factor time = Time:GetCurrent()/1000 context:SetBlendMode(1) context:SetColor(self.color) context:SetFont(self.font) context:DrawText(Math:Round(time),w,h,r,r,Text.VCenter+Text.Center) context:SetFont(defaultFont) end Quote
GTkoi Posted September 24, 2019 Author Posted September 24, 2019 Okay, but where do I put the code? On an object? Quote
havenphillip Posted September 24, 2019 Posted September 24, 2019 Yeah put a pivot in the scene and attach the script to the pivot. The pivot can be anywhere on the map. It doesn't matter because the PostRender() stuff will show up in the same place on screen regardless. Quote
GTkoi Posted September 25, 2019 Author Posted September 25, 2019 ok but, I don't have the font "brianjames.ttf " x) . So is does not work... Quote
GTkoi Posted September 25, 2019 Author Posted September 25, 2019 no it's good I found a another font to put, thank you for your answers ... Quote
GTkoi Posted September 25, 2019 Author Posted September 25, 2019 Another problem, when I press escape to put the game on pause, the timer comes off the screen... Quote
havenphillip Posted September 26, 2019 Posted September 26, 2019 Yeah, man. That's a little quirk in the system that I guess Josh never got around to straightening out. Go to Scripts folder, and find "Main.lua". Open that and look for this: if gamemenu:Hidden() then --Update the app timing Time:Update() --Update the world world:Update() end --Render the world world:Render() ...then right before "world:Render()" add this line: gamemenu.gui:GetBase():Redraw() Quote
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.