I'M BACK! I'm trying to load a special font for the health percentage in my game; Loading the font goes by smoothly, but when I actually try to set the font it crashes. I know the font isn't nil (I tested it) and it can't be the font I'm using because it's the default font, except with a different size. Anyways, here's some code:
local window = Window:GetCurrent()
local forward = 0
local strafe = 0
local angle = 0
local firing = false
local shootTimer = 0
local health = 100
local pickInfo = PickInfo()
function Script:Start()
self.w1 = Texture:Load("Materials/HUD/gun_overlay.tex")
self.w1f = Texture:Load("Materials/HUD/gun_overlay_02.tex")
self.ch = Texture:Load("Materials/HUD/crosshair.tex")
self.hb = Texture:Load("Materials/HUD/healthbar.tex")
self.entity:SetKeyValue("weapon", "blaster")
self.entity:SetKeyValue("type", "player")
self.font = Font:Load("Materials/Fonts/arial.ttf",36)
local material = Material:Create()
material:SetBlendMode(5)
self.entity:SetMaterial(material)
material:Release()
end
function Script:UpdateWorld()
window = Window:GetCurrent()
angle = angle - dx * 0.25
local jump = 0
if window:KeyDown(Key.Space) and self.entity:GetAirborne() == false then
jump = 10
end
if window:MouseHit(1) and firing == false and self.entity:GetKeyValue("weapon") ~= "none" then
firing = true
local p0 = self.entity:GetChild(0):GetPosition(true)
local p1 = Transform:Point(0,0,20,self.entity:GetChild(0),nil)
self.entity.world:Pick(p0,p1, pickInfo, 0, true)
if pickInfo.entity ~= nil then
if pickInfo.entity:GetKeyValue("type") == "enemy" then
pickInfo.entity:SetKeyValue("hurt", "true")
end
end
end
if firing == true and shootTimer < 24 then
shootTimer = shootTimer + 1
elseif firing == true and shootTimer == 24 then
shootTimer = 0
firing = false
end
forward = (window:KeyDown(Key.W) and 1 or 0)*6 - (window:KeyDown(Key.S) and 1 or 0) * 6
strafe = (window:KeyDown(Key.D) and 1 or 0)*6 - (window:KeyDown(Key.A) and 1 or 0) * 6
self.entity:SetInput(angle, forward, strafe, jump, false)
onGround = false
end
function Script:PostRender(context)
context:SetBlendMode(Blend.Alpha)
context:SetColor(1,1,1,1)
context:DrawImage(self.ch, 400 - 16, 300 - 16)
--context:DrawImage(self.hb, 0, 600 - 104)
context:SetFont(self.font)
context:DrawText("Health: "..health.."%", 160, 600 - 72)
end