Jump to content

Multiple fonts


Core
 Share

Recommended Posts

small example:

window = Window:Create("font example",0,0,400,300)

context = Context:Create(window)

world = World:Create()

camera = Camera:Create()

light = DirectionalLight:Create()

light:SetRotation(45,45,0)

box = Model:Box()

box:SetPosition(0,0,3)

box:SetColor(1,0,0,1)

 

lilfont = context:GetFont()

bigfont = Font:Load("Fonts/arial.ttf", 48, 1)

 

toggle = 0

 

while window:KeyDown(Key.Escape)==false do

if window:Closed() then break end

 

box:Turn(Time:GetSpeed()*0.5,Time:GetSpeed()*0.5,0)

 

if window:KeyHit(Key.Space) then toggle = 1 - toggle end

if toggle==0 then

context:SetFont(lilfont)

else

context:SetFont(bigfont)

end

 

Time:Update()

world:Update()

world:Render()

context:SetBlendMode(Blend.Alpha)

context:DrawText(string.format("FPS: %.2f",Time:UPS()),0,10)

context:DrawText("HIT SPACE",0,80)

context:Sync(true)

end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Thank you very much. context:SetFont was the key part I missed. Here is my current progress with Tittle screen:

 

Why tab is not working I don't know, sorry a bit hard to read...

 

function Script:Start()

self.Tittle = "Tittle"

self.Tittle2 = "Subtittle"

self.Menutext1 = "Press ENTER"

font1 = Font:Load("Fonts/LCD-N.ttf", 100)

font2 = Font:Load("Fonts/arial.ttf", 30)

font3 = Font:Load("Fonts/LCD-L.ttf", 30)

return true

end

 

function Script:UpdateWorld()

if window:KeyDown(Key.Enter) then

self.component:CallOutputs("Activate")

end

end

 

function Script:PostRender()

self.DisplayEnabled = true

if self.DisplayEnabled == true then

context:Clear()

context:SetFont(font1)

local font1 = context:GetFont()

local screenwidth = window:GetWidth()

local screenheight = window:GetHeight()

local x = screenwidth/2

local y = screenheight/2

context:SetBlendMode(Blend.Alpha)

context:SetColor(0,0,0)

context:DrawRect(0,0,screenwidth,screenheight,0)

context:SetColor(1,0,0)

local font1_x = (screenwidth - font1:GetTextWidth(self.Tittle))/2

local font1_y = (screenheight - font1:GetHeight())/2

context:DrawText(self.Tittle,font1_x,font1_y-200)

context:SetFont(font2)

context:SetColor(1,1,1)

context:DrawText(self.Tittle2,x+80,y-130)

local font3_x = (screenwidth - font3:GetTextWidth(self.Menutext1))/2

local font3_y = (screenheight - font3:GetHeight())/2

context:SetFont(font3)

context:DrawText(self.Menutext1,font3_x,font3_y+200)

end

context:SetBlendMode(Blend.Solid)

end

 

I'm just getting a bit frustrated for the lack of documentation... I understand that this is a one big learning experience, but feels that I spend too much time searching from the net and combining different pieces of information in to one just to put up some very basic tittle screen, for example. Every game needs an UI! There should be official tutorial for it!

 

Next step is to learn to load map after pressing enter on tittle screen, and it sounds simple enough, but I'm allready sure it is not that simple...

 

But, sorry for ranting, I love Leadwerks still :) I'm more angry at myself and my thick head.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...