Currently the developers are putting their own money into JC2-MP to keep the servers online.

Please take a few seconds of your time and disable your AdBlock plugin for our website.

Ad revenue is not going to developers, it is used purely for covering our hosting costs.

 

You are also free to donate, which removes all ads from our website!

Patch 0.3 was just released! Full changelog here: https://t.co/4A50m6IKen

4 years ago

Advertisement
December 01, 2020, 12:01:55 am

Author Topic: Render.GetTextSize is not accurate when using scale  (Read 101 times)

DaAlpha

  • Donator
  • Jr. Member
  • *****
  • Posts: 60
    • View Profile
Render.GetTextSize is not accurate when using scale
« on: November 08, 2020, 09:04:12 pm »
Steps to reproduce:

Code: Lua
  1. print(Render:GetTextSize("This should be the same", 16, 1.5))
  2. print(Render:GetTextSize("This should be the same", 16) * 1.5)

Output:
Code: [Select]
20:57:25 | [info ] | [_test] 267.000000, 24.000000
20:57:25 | [info ] | [_test] 259.500000, 24.000000

My global text scale is set to 1.0.

Additional information:

It seems to jump around in steps, as can be seen using this code:

Code: Lua
  1. local scale = 1
  2. local down  = false
  3.  
  4. Events:Subscribe("Render", function(args)
  5.   local delta = args.delta * 0.1
  6.   if down then
  7.     delta = -delta
  8.   end
  9.  
  10.   scale = scale + delta
  11.   if scale <= 0.5 or scale >= 2 then
  12.     down = not down
  13.   end
  14.  
  15.   local fontSize  = 16
  16.   local text      = "Sample Text"
  17.   local textSize1 = Render:GetTextSize(text, fontSize) * scale
  18.   local textSize2 = Render:GetTextSize(text, fontSize, scale)
  19.   local textPos   = Vector2(Render.Width * 0.5, Render.Height * 0.25)
  20.  
  21.   Render:FillArea(textPos, textSize1, Color.White)
  22.   Render:FillArea(textPos, textSize2, Color.Red)
  23.   Render:DrawText(textPos, text, Color.Black, fontSize, scale)
  24.  
  25.   Render:DrawText(textPos - Vector2(0, 18), string.format("Scale: %.3f", scale), Color.White)
  26. end)

« Last Edit: November 08, 2020, 09:46:09 pm by DaAlpha »