bansama Posted July 27, 2014 Share Posted July 27, 2014 Sorry for another question which probably has a dead easy answer, but we have to learn somewhere right? I'm trying to display text on screen for a specific time. Basically, when I "use" an object, I want to display related text for a seconds. I was hoping some kind of while loop to count down the specified amount of time would work, but it had less than desirable results. FPS drops, text not displaying, etc. Any suggestions on what I should be doing? function Script:Use(context) self.Used = "1" end function Script:PostRender(context) if self.Used == "1" then local font = Font:Load("Fonts/arial.ttf", 12) App.context:SetFont(font) if self.ObjectDescription ~="" then local DisplayTime = 0 while DisplayTime < self.DisplayTimeMax do App.context:SetBlendMode(Blend.Alpha) context:DrawText(self.ObjectDescription, 102, 22) App.context:SetBlendMode(Blend.Solid) DisplayTime = DisplayTime + 1 end end self.Used = "0" end end Quote Link to comment Share on other sites More sharing options...
Xmlspy Posted July 27, 2014 Share Posted July 27, 2014 You could try using Time:GetCurrent() to deal with the specific amount of time. By the way, does pressing F11 drop your FPS that much? Setup: Script.timeStartandDuration = 0 Script.displayEnabled = false Use this when you want to begin the timer: self.timeStartandDuration = Time:GetCurrent() + 5000 -- 5 seconds in this case self.displayEnabled = true Use this where you update: if self.displayEnabled == true then if self.timeStartandDuration > Time:GetCurrent() then -- Draw stuff code here else self.displayEnabled = false end end I'm sure you can be far more elegant than me on the names of the variables. Hope that helps. Quote Link to comment Share on other sites More sharing options...
bansama Posted July 27, 2014 Author Share Posted July 27, 2014 You could try using Time:GetCurrent() to deal with the specific amount of time. By the way, does pressing F11 drop your FPS that much? Thanks! I had looked at Time: but hadn't realised I could use it that way. Silly really, as I used to use similar in PHP years ago (I'm very rusty with coding). But thanks to your help, I now have something to work with! Pressing F11 itself doesn't drop frame rate no, but the default set up in App.lua has any rendering toggled off with F11. I did try to create a new window, etc., to render text to, but that never worked with either Assert failed crashes or other errors. I've since added a section after the F11 toggle which seems to help. So the relevant section in App.lua now looks like this: --Render statistics self.context:SetBlendMode(Blend.Alpha) if DEBUG then self.context:SetColor(1,0,0,1) self.context:DrawText("Debug Mode",2,2) self.context:SetColor(1,1,1,1) self.context:DrawStats(2,22) self.context:SetBlendMode(Blend.Solid) else --Toggle statistics on and off if (self.window:KeyHit(Key.F11)) then self.showstats = not self.showstats end if self.showstats then self.context:SetColor(1,1,1,1) self.context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2) end -- Allows text to be rendered when FPS is toggled off self.context:SetColor(1,1,1,1) self.context:DrawText("", 0, 0) end I do get frame rate drops, but only when outputting with System:Print() which I use from time to time to help with debugging. And that was the cause of my FPS drops I think with the While loop I was testing. 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.