Glitchy Text In Menu

Started by boaromayo, April 25, 2019, 02:32:20 PM

Previous topic - Next topic
April 25, 2019, 02:32:20 PM Last Edit: April 25, 2019, 02:37:57 PM by boaromayo
Hey everyone, there's something I spotted while play-testing my game on the 1.6 Solarus launcher.

The main menu screen (seen here) looks glitchy. Also, the text there was drawn in the wrong place, or squished up together. Was it because of the font I'm using, or was it because of an issue in the game engine itself?

Also, these two errors popped up in the 1.6 version:


Error: Invalid tile pattern '169: a tile pattern with a diagonal wall must be square
Error: Invalid tile pattern '171: a tile pattern with a diagonal wall must be square


Note when I play-tested the game on the 1.5 version, no problems came up.

Could those errors be related to the glitches in the menu?

When you do drawable:draw_region(), if the source rectangle is bigger than the size of the drawable (which would be a mistake from your script), Solarus 1.6 gives a different result than Solarus 1.5. Just fix this in your script and it should be fine.

About the invalid tile pattern, 1.5 was probably verifying less things than 1.6. Solarus 1.6 detects more errors and reports them. So similarly, you can just go fix your tileset according to the error messages.

April 25, 2019, 04:48:24 PM #2 Last Edit: April 25, 2019, 04:52:33 PM by boaromayo
Thanks for the help and quick response!

When drawing the menu text out, I did not use drawable:draw_region(). I used drawable:draw() instead. Also, I used text surfaces instead of surfaces.

Plus, the font I'm using is a bitmap font.

Here's a sample of my code that prints out the menu and the options:


-- Sample code printing out text for the menu.
function demo_screen:load_resources()

  -- Code here...

  self.menu_text = sol.text_surface.create({
      font = font
  })

  -- More code here...
end

-- Drawing function for main demo.
-- This function is a sub-function for the main drawing function.
function demo_screen:on_draw_main_demo()
  self.surface:clear()

  -- Text for select title.
  self.menu_text:set_text_key("demo_screen.select")
  self.menu_text:draw(self.surface,
    box_width / 2 - 24, self.box_position.y + 24)

  -- Text for choices.
  for i = 1, #self.choices-1 do
    self.menu_text:set_text_key(self.choices[i])
    self.menu_text:draw(self.surface, self.box_position.x + 24, (i-1) * 24 + 100)
  end

  -- More code here...
end

-- Main drawing function.
function demo_screen:on_draw(screen)

  -- Code here...
  self:on_draw_main_demo()

  local width, height = screen:get_size()
  self.surface:draw(screen, width / 2 - 160, height / 2 - 120)
end


I'll see if using drawable:draw_region() works.

So, I used drawable:draw_region() in place of drawable:draw(), and put the region widths for the glitchy text more than the texts' widths, but the texts are still glitchy when I played the game in 1.6.

I noticed that the text glitching is apparent when the game fades in to the menu.

I'm still thinking the text glitches might be an issue with the engine itself, but I'm not so sure.

I've noticed that Solarus v1.6 seems to be glitchy with text surfaces if text_surface:set_text() or text_surface:set_color() are called within an on_draw() function (which didn't happen in v1.5).

Try moving the self.menu_text:set_text_key() lines outside of the demo_screen:on_draw_main_demo() function and see if that helps.

Yes. on_draw() should only draw, and not change the state.

I managed to finally fix that bug!

I took @llamazing's advice and took out all the set_text_key() calls in each of the drawing methods, and placed them in initialization methods.

It turns out that every time the set_text_key() was called in the loop, the text gets drawn next. In turn, the loop would repeat, and would result in that glitch.

Thank you again for the help!