I tried to implement that script, but Solarus told me it couldn't get the camera because map was a nil value. I'm not totally sure, but I think that when the game is first started, the map has not been set yet, so it's nil. Then later the map gets set and then the map gets started.
I've been studying up on the Solarus documentation a bit, and I thought to perhaps try something like the following code, where I add these camera settings to the on_started() of every map.
require("scripts/multi_events") --This is required for this script to work. It allows the script to be called on its own.
print("Hello") --Used for testing
local map_meta = sol.main.get_metatable("map")
map_meta:register_event("on started", function()
camera = self.get_camera()
camera:set_size(256, 160)
camera:set_position_on_screen(0, 16)
print("World") --Used for testing
end)
This code is in a script called "camera_settings" which I have required in my main.
Unfortunately this is not working either. I'll get "Hello" but no "World," and the camera is not changed. So it would seem that it's not actually registering this function into the on_started() for my maps. Perhaps this is not a great way to do things either, but I don't quite understand what isn't working here.
I followed this code as a guide from the API for sol.main.get_metatable(type):
-- Somewhere in your main script, at initialization time:
local map_metatable = sol.main.get_metatable("map")
function map_metatable:add_overlay(image_file_name)
-- Here, self is the map.
self.overlay = sol.surface.create(image_file_name)
end
function map_metatable:on_draw(dst_surface)
if self.overlay ~= nil then
self.overlay:draw(dst_surface)
end
end
-- Now, all your maps will have a function map:add_overlay() and an event
-- map:on_draw() that allows to draw an additional image above the map!