Draw text

Started by Yruama, June 28, 2015, 07:44:03 PM

Previous topic - Next topic
I try to draw text in the middle of screen when the player enter in a dungeon.

I try this :

local map = ...
local game = map:get_game()
local surface = sol.surface.create(320, 240)

function map:on_started()
local dialog_font, dialog_font_size = sol.language.get_dialog_font()
  local menu_font, menu_font_size = sol.language.get_menu_font()

dungeon_name = sol.text_surface.create {
    font = menu_font,
    font_size = menu_font_size,
    color = {240, 200, 56},
    text_key = "dungeon.name.0",
    horizontal_alignment = "center"
  }
    dungeon_name:draw(surface)
end


But it does not work. I have no error.

June 28, 2015, 10:05:42 PM #1 Last Edit: June 28, 2015, 10:45:27 PM by Diarandor
As far as I know (maybe I am wrong), I think that your problem is that you need to draw it at each "iteration" (your code draws it during a quick "instant" and then disappears, so you don't see it).

I would try to use the method dungeon_name:draw(surface) inside the method on_draw() of a menu, that will be automatically drawn at each iteration (the engine makes the work). (The same happens when you draw sprites on map entities, which are usually drawn by the engine at each iteration, which does not happen in general.) Maybe you can make your surface become a menu or something like that...
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."