Author Topic: How to show a night overlay on a map  (Read 2659 times)


  • Administrator
  • Hero Member
  • *****
  • Posts: 1181
    • View Profile
How to show a night overlay on a map
« on: August 08, 2013, 10:01:39 am »
Solarus has a few built-in mechanisms, and you can customize things through the Lua API.
For example, there is no built-in day/night system. But it is easy to create one. In this sample script, we will make a simple dark overlay on the map to make a night visual effect.

More generally, you can use the same code to show any kind of semi-transparent surface on the map, even a PNG image.

For more details, see the documentation of surfaces.

First, create a surface for your map, for example in map:on_started() in your map script:

Code: [Select]
function map:on_started()
  self.night_overlay = sol.surface.create()  -- Create an empty surface of the size of the screen.
  self.night_overlay:set_opacity(192)        -- Make it semi-transparent (0: transparent, 255: opaque).
  self.night_overlay:fill_color({0, 0, 64})  -- Fill it with dark blue to obtain a night effect.

The night surface is initialized, we just have to draw it when the map is drawn:
Code: [Select]
function map:on_draw(destination_surface)

And voilĂ  !

So this is the basic idea.

If you want more:
- (Easy) To make the opacity change with time, use a timer.
- (Easy) To show an image from an external file instead, replace sol.surface.create() by sol.surface.create("path/to/file.png").
- (Advanced) To make the image move when the player moves (like the lost woods overlay in ALTTP), there are two optional parameters x and y in map.night_overlay:draw(). How to determine appropriate x and y values is left as an exercise to the reader ;)
- (Advanced) To make the image move automatically (like clouds), create a movement on your image.
- (Advanced) You can also combine the previous two remarks.
« Last Edit: August 08, 2013, 11:11:12 am by Christopho »


  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: How to show a night overlay on a map
« Reply #1 on: August 15, 2015, 06:40:41 pm »
Is is also possible to have two overlays at the same time.

I have the forest overlay, but i want also the night overlay, mentioned above, on the same time.