I'm building a racing game, and I'm running into trouble getting my clock element to display correctly. I want to have the clock displayed as a 3d object on a scoreboard, and it does just that. However, while the element displays the correct time, it does not display the correct width of the digits.
Here is the code for the section in question. Everything works except the width determination for the object.
`display time
if OldTime<>NewTime `only run if one second has passed
GetTimeDigits() `assigns time digits in proper places
`make all elements, detect size of all elements, position at midpoint relative to size
for P = 3 to 6
`delete old time objects
if StatOb(0,P)>0
if object exist(StatOb(0,P))=1 then delete object StatOb(0,P)
endif
`build new time object based on digit value
`pull data from the numeral of the digit.
WH(0,P)=image width(digit(0,StatVal(0,P)))
WH(1,P)=image height(digit(0,StatVal(0,P)))
`build new time object based on digit value
StatOb(0,P)=nobplane(TDH#*WH(0,P)/WH(1,P),TDH#)
texture object StatOb(0,P),digit(0,StatVal(0,P))
next P
`get total width of time element
TotalTimeWidth#=TimeObWidth#+TimeColonWidth#+object size x(StatOb(0,3))+object size x(StatOb(0,4))+object size x(StatOb(0,5))+object size x(StatOb(0,6))
`SBMx# is the midpoint to center things on
`"TIME" object
position object StatOb(0,1),SMBx#-TotalTimeWidth#*.5,DisplayHeight#,TimeZ#
`minutes 10 digit
position object StatOb(0,6),Object position x(StatOb(0,1))+object size x(StatOb(0,1))*.5+object size x(StatOb(0,6))*.5,DisplayHeight#,TimeZ#
`minutes 1 digit
position object StatOb(0,5),Object position x(StatOb(0,6))+object size x(StatOb(0,6))*.5+object size x(StatOb(0,5))*.5,DisplayHeight#,TimeZ#
`a colon :
position object StatOb(0,2),Object position x(StatOb(0,5))+object size x(StatOb(0,5))*.5+object size x(StatOb(0,2))*.5,DisplayHeight#,TimeZ#
`seconds 10 digit
position object StatOb(0,4),Object position x(StatOb(0,2))+object size x(StatOb(0,2))*.5+object size x(StatOb(0,4))*.5,DisplayHeight#,TimeZ#
`seconds 1 digit
position object StatOb(0,3),Object position x(StatOb(0,4))+object size x(StatOb(0,4))*.5+object size x(StatOb(0,3))*.5,DisplayHeight#,TimeZ#
endif
function GetTimeDigits()
`get minutes value from seconds
Seconds=StatVal(0,0) mod 60
Minutes=(StatVal(0,0)-Seconds)/60
`store values into array
StatVal(0,3)=Seconds mod 10 `ones digit
Seconds=Seconds/10
StatVal(0,4)=Seconds mod 10 `tens digit
StatVal(0,5)=Minutes mod 10 `ones digit
Minutes=Minutes/10
StatVal(0,6)=Minutes mod 10 `tens digit
endfunction
`build plane of X,Y and align to the view
function nobplane(x,y)
P=1
repeat
if object exist(P)=1 then inc P
until object exist(P)=0
make object plane P,x,y
point object P,0,1,0
yrotate object P,180
set object transparency P,1
endfunction P
And here is the width determination dissected. The WH() array is a float value.
This gets the width and height of image that will be the texture on the plane.
WH(0,P)=image width(digit(0,StatVal(0,P)))
WH(1,P)=image height(digit(0,StatVal(0,P)))
This builds the plane. TDH# is the height of the element. When I do this math on pen and paper, it produces accurate size results. It uses the formula ObjectWidth/ObjectHeight=ImageWidth/ImageHeight and solves for Object Width.
StatOb(0,P)=nobplane(TDH#*WH(0,P)/WH(1,P),TDH#)
Despite the number images having different widths and heights (the widths range from 22 for the 1 to 40 for the 0, the heights are 49-51), the width for every object is exactly the same. I've bugtested the code, and every value is correct except for the calculated width, which is always constant.
I cannot figure out why it's constant. The old objects are deleted, and new objects are created with a width of TDH#*WH(0,P)/WH(1,P). WH(0,P) and WH(1,P) are filled with the correct image size values. TDH# = 2.382. When I solve the equations on paper, I get an object width value that varies based on the dimensions of the image. But the program always returns the same value for each object, despite having different images.
edit: edited code for clarity, added more remtags. These forums could use a preview post button...