Text position detection thing or something

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
Tribeam
Prole
Posts: 2
Joined: Tue Oct 25, 2011 9:00 pm

Text position detection thing or something

Post by Tribeam »

I'll let the image explain itself
kjpoK.jpeg
kjpoK.jpeg (74.64 KiB) Viewed 176 times
So yeah, scrolling the text isn't a problem, it's the part that says "TEXT JUST GOT TO THIS POINT DO SOMETHING" heh..

Thanks.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Text position detection thing or something

Post by bartbes »

There is getWrap, which even accounts for embedded newlines, but it is kind of broken in 0.7.2, and, more importantly, it doesn't help you determine where to wrap.
If you have it line-by-line, you can just do the math with Font:getHeight.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Text position detection thing or something

Post by kikito »

You are not giving much information (nor showing us any code, tsk tsk) so it's a bit difficult to help you.

Assuming that:
  • You have a table representing the console "buffer" (the lines on the screen) and
  • That you now how many lines you can print at maximum
Then you can do something similar to this:

Code: Select all

function getMaxLinesShownInConsole()
  return 14 -- as per your example
end

function addLineToConsole(line)
  if #currentLines < getMaxLinesShownInConsole() then
    table.remove(currentLines, 1) -- remove the "top" line from the console list.
  end
  table.insert(currentLines, line) -- insert the new line at the bottom.
end
If you need more flexibility than that (for example, if the spacing between lines is flexible, or the console area is not always the same) then you will have to calculate something more complex on getMaxLinesShownInConsole().

As bartbes says, there's Font:getHeight, but you are probably using a fixed line height, or you would have discovered it already. So probably you only need something along the lines of "consoleAreaHeight / lineHeight" for a more flexible getMaxLinesShownInConsole().

Regards!
When I write def I mean function.
Tribeam
Prole
Posts: 2
Joined: Tue Oct 25, 2011 9:00 pm

Re: Text position detection thing or something

Post by Tribeam »

Heh, I feel like a fool, after getting some needed sleep I came up with a solution rather quickly and easily(it'll get more advanced as i go along though)

Code: Select all

function ConsoleLog(text)
	table.insert(table_consolebuffer, text);
	int_consoletextpos = int_consoletextpos - 15;
end
...
for i, lines in ipairs(table_consolebuffer) do 
	love.graphics.printf(lines, 20, int_consoletextpos + (i * 15), love.graphics.getWidth() - 20, "left"); 
end
Basically it adds a line at the bottom of the console, and moves the rest of the text up, completely shattering all my problems, which is how it should of worked in the first place.
This is why programmers should not code while extremely tired heh.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], NoreoAlles and 9 guests