Jump to content
GTkoi

Help me PLZ !!

Recommended Posts

I have two problem :

I would like restart the timer, when I change the map ...

And the seconde : When I change font size for the text on the screen, it also change the police size in the menu option, and I do not want the font of the menu changes ...


 

 

Share this post


Link to post

Changing font is a state kind of action. When you change it, it's then set for all drawing of text. So you have to change it, draw your text, then change it back to what it was.

 

What timer are you talking about? You have some timer code somewhere? We'd have to see it.

Share this post


Link to post

yes, my code for timer is :

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

Share this post


Link to post
6 hours ago, Rick said:

Changing font is a state kind of action. When you change it, it's then set for all drawing of text. So you have to change it, draw your text, then change it back to what it was.

 

What timer are you talking about? You have some timer code somewhere? We'd have to see it.

ok but how do i change the font size of the ecape menu (in main.lua) 
without changing the font size of the text on the screen?

Share this post


Link to post

The clock isn't restarting because the script is calling Time:GetCurrent(). When you change maps the application doesn't restart, so it's counting the application running time. So what you need is Time:GetSpeed(). That's probably a better way to do a timer anyway.

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
Script.countSpeed = 0.05 -- float "Count Speed" (smaller is slower)
Script.time = 0

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:UpdateWorld()
    self.counter = Time:GetSpeed() * self.countSpeed
    self.time = self.time + self.counter
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

    context:SetBlendMode(1)
    context:SetColor(self.color)
    context:SetFont(self.font)
    context:DrawText(Math:Round(self.time),w,h,r,r,Text.VCenter+Text.Center)

    context:SetFont(defaultFont)
end

Not sure what you mean by the font sizes. You want to change the font in the gui?
 

Share this post


Link to post

Thanks for help, I would like change the font size to my code "text on the screen" without change font size In GUI

(when I change the size in the code, it also changes the font size elsewhere, so that I do not want)

Share this post


Link to post

In the above timer script you have to use  "defaultFont = context:GetFont()" at the start of your PostRender() function, then you set the font to the font you want with " context:SetFont(self.font) ", then you "DrawText(...)" and after you have to set it back to the default font with " context:SetFont(defaultFont)." I'm guessing you have other scripts that use the DrawText() function? You have to use "defaultFont = context:GetFont()" and " context:SetFont(defaultFont) " in every script that uses "DrawText(...)".

Basic Font script:
This shouldn't change your other fonts because you're resetting the font back to the default here:

Script.myFont = "" --path "Font"
Script.color = Vec4(1,1,1,1) --color "Color"
Script.size = 12

function Script:Start()

    self.myFont= Font:Load(self.myFont,self.size)
end

function Script:PostRender(context)

    defaultFont = context:GetFont() --at start of every postrender function
    
    context:SetBlendMode(1)
    context:SetColor(self.color)
    context:SetFont(self.myFont) -- changed to your font
    context:DrawText("My Text" ,20,20,100,100)
    
    context:SetFont(defaultFont) -- change font back to default at end of every postrender function anywhere "SetFont()" and "DrawText()" are used
end

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...