Text in front of Geometry

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Pardaleco
Prole
Posts: 10
Joined: Mon Dec 31, 2018 7:12 pm

Text in front of Geometry

Post by Pardaleco »

Is there a way for me to get some text using love.graphics.print in front of rectangles created by love.graphics.rectangle ??

Example I created some recangles using

Code: Select all

world = {}

function CreateObject(x, y, w, h)
  return {position = vector2.new(x, y), size = vector2.new(w, h)}
end

function LoadWorld()
  world[1] = CreateObject(0,0,1400,200) --ceiling
  world[2] = CreateObject(0,800-200,1400,200) --floor
end

function DrawWorld(world)
  for i = 1, table.getn(world), 1 do
    love.graphics.rectangle("fill", world[i].position.x, world[i].position.y, world[i].size.x, world[i].size.y)
  end
end
And I want this next text which is a timer to be on top of the ceiling rectangle

Code: Select all

countdown = 5

function Countdown(dt)
  if countdown > 0 then
    countdown = countdown - dt
  end
  if countdown == 0 then
    countdown = countdown 
  end
  
end

function Drawtimer()
  love.graphics.setColor(0,0,0)
  love.graphics.setDefaultFilter("nearest", "nearest")
  local timerfont = love.graphics.newFont("edosz.ttf", 25)
  love.graphics.setFont(timerfont)
  local round = string.format("%.1f", countdown)
  love.graphics.print("time: " .. round, 60, 300)
  love.graphics.setColor(1,1,1)
end
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Text in front of Geometry

Post by zorg »

Without seeing the code that calls DrawWorld and Drawtimer, i'm assuming it looks somewhat like this; note the order:

Code: Select all

Drawtimer(w)
DrawWorld(w)
If that's the issue, then if you draw the timer last, it will be on top of everything that has been drawn before it; simple as that.


On the other hand, don't create new fonts each time you call something as repetitive as a function that runs every frame; just have timerfont defined and created elsewhere.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Pardaleco
Prole
Posts: 10
Joined: Mon Dec 31, 2018 7:12 pm

Re: Text in front of Geometry

Post by Pardaleco »

Thank you zorg! It was really that simple :s!

And again, thank for the advice on the font, I love efficiency so that helps!
Thank you again
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests