RenderText

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

RenderText

Post by y offs et »

How FloatMultiply operates remains mystery. I set up this for testing.
Attachments
rendTextNum.zgeproj
(491 Bytes) Downloaded 451 times
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:)

Never used it like that myself .. only to multiply by 10 / 100 / 1000 etc.

Anyway, the RenderText component only displays the part of a float that is in front of the decimal ( so the behavior is similar to when you'd truncate a float to a integer ).

2*0.49 = 0.98
2*0.50 = 1.00
2*0.51 = 1.02

Also, you don't have to put the "n=2.0" assignment in the OnUpdate event since the RenderText component doesn't actually apply the multiplication to the variable ( uses a internal variable / property instead ). Neither do you have to write "2.0" .. just "2" is sufficient ( unlike for GLSL ).

K
User avatar
Kjell
Posts: 1924
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

8)

Function for converting a float to a string ( including decimal separator ). First argument is the float, second is the number of fractions you want to show.

Code: Select all

string floatToStr(float X, int N)
{
  string F, S;

  if(X < 0)S = "-"; else S = "+";

  float P = pow(10,N);
  F = intToStr(floor(abs(frac(X)*P)));
  while(length(F) < N)F = "0"+F;

  return S+intToStr(abs(X))+"."+F;
}
K
Post Reply