Page 1 of 1
Text position detection thing or something
Posted: Tue Oct 25, 2011 9:04 pm
by Tribeam
I'll let the image explain itself
- kjpoK.jpeg (74.64 KiB) Viewed 267 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.
Re: Text position detection thing or something
Posted: Tue Oct 25, 2011 9:17 pm
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.
Re: Text position detection thing or something
Posted: Tue Oct 25, 2011 9:36 pm
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!
Re: Text position detection thing or something
Posted: Wed Oct 26, 2011 3:02 am
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.