Super duper early WIP monster fighting game. Literally only a menu that does nothing. Up and down to move the cursor.
I am mostly uploading right now to ask for help. If you open the game you'll see I have a little border drawn and am putting text inside of it. Is there any way to draw text in here more easily? The naive approach of printing each time leaves leftover text. My thought was to us rectfill
but then the text doesn't print over it (despite calling print
afterwards). I've put the relevant code below of what I'm using. My thought it to just use solid background (\#0 control code
) but this would still mean I need to print over the full area each time (by padding).
This just seems like it would be something more textual games have run into before and I was wondering what the approach is.
Thanks!
function _draw() -- ...snip... draw_menu() end menu={"fight", "item", "run"} selection=0 function draw_menu() local text="" for k,v in pairs(menu) do if selection==k-1 then text..="➡️" else text..=" " end text..=v.."\n" end textbox(8, 72, 112, 48, text) end -- 8, 72, 112, 48 for full area function textbox(x, y, w, h, text) --rectfill(x, y, x+w-1, y+h-1, 0) --[[rhs wrap based on absolute x, not offset from print call]] local num_chars = to_fake_hex_str(flr((x+w)/4)) print("\#0\^r"..num_chars..text, x, y) end |
print()
can take a colour argument, similar to rect. whenever you provide a colour it sets the default colour for everything you draw afterwards. you can also set this default colour using the color()
function.
Thanks! That did the trick. I suppose I understood color being optional to mean a default color as opposed to the last used color. Resetting it to 6 indeed works. I guess earlier the all black screen was actually just black text on black background lol.
function textbox(x, y, w, h, text) rectfill(x, y, x+w-1, y+h-1, 0) --color(6) or color() also work local num_chars = to_fake_hex_str(flr((x + w) / 4)) print("\^r"..num_chars..text, -- note the removal of \#0 x, y, 6) -- note the 6 end |
[Please log in to post a comment]