Author Topic: Draw text  (Read 1564 times)

Yruama

  • Newbie
  • *
  • Posts: 24
    • View Profile
Draw text
« on: June 28, 2015, 07:44:03 pm »
I try to draw text in the middle of screen when the player enter in a dungeon.

I try this :

Code: [Select]
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.

Diarandor

  • Hero Member
  • *****
  • Posts: 1061
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Draw text
« Reply #1 on: June 28, 2015, 10:05:42 pm »
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...
« Last Edit: June 28, 2015, 10:45:27 pm by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”