Solarus > Development

How to configure game window

(1/4) > >>

CopperKatana:
Hello, I'm trying to do a Solarus recreation of Golden Axe Warrior on the Sega Master System, a Zelda clone that has since been considered a hidden gem of the system.
I am trying to adjust various aspects of the display such that it closely resembles the setup of the original game. You can see my project in Solarus and a screenshot of the original game at the imgur link on the bottom.
In the original game, the map only takes up part of the screen, and the rest of the screen is colored black. I would like to replicate this if possible. What scripts or files should I edit to achieve this?

https://imgur.com/a/bGcLKX6

PhoenixII54:
It is perfectly possible to achieve this HUD style, by using the camera API to resize and place it on the screen at game initialization time (generaly in the game:on_started event). For the HUD itself, you will likely want to place it in a menus/hud.lua menu script, and use the menu:on_started and menu:on_draw events to build and update the surfaces which you will display on the screen. See this page for more informations about menus, and don't hesitate to peek a view into the team's games to have an inside of their inner works.

Bonus track: you can display the amount of money(?) as "000" using string.format("%03i", your_variable) when building the text surface for the HUD

CopperKatana:
Thanks for the reply. I've been fiddling for a while but I'm having trouble understand how Solarus organizes scripts. If I want to put a camera:set_size() call in game:on_started(), what script file would I put it in? Or would I make a new script?

Kamigousu:

--- Quote from: Blueblue3D on July 17, 2019, 02:37:09 am ---Thanks for the reply. I've been fiddling for a while but I'm having trouble understand how Solarus organizes scripts. If I want to put a camera:set_size() call in game:on_started(), what script file would I put it in? Or would I make a new script?

--- End quote ---

You could create a new script. Not sure what your directory looks like but if you have nowhere to put it all ready you could create a game.lua file either in the scripts folder or, optionally, in a subfolder you create called meta.

The script would use metatables so if you aren't familiar with them, it may be confusing. I'm not entirely familiar with them so what I have to say will be pretty basic, I think. It would also require the multi_events script that the solarus team has generously shared with their game files.

The following should change the camera size everytime the game is started; although I can't say that this will be the best or most efficient way to do this:

--- Code: ---require("scripts/multi_events")  --This is required for this script to work. It allows the script to be called on its own.

local game_meta = sol.main.get_metatable("game")
game_meta:register_event("on_started", function()   local map = game:get_map()
                                        local camera = map:get_camera()

                                        camera:set_size(width, height)  --size will be replaced with the size of the camera on screen.
                                         --If your screen is the standard 320x240 then you could make                                           
                                         --the camera 320, 200 and it should leave a black bar at the bottom of the screen.

end)

--- End code ---

then just require your game.lua script in either the main script (messy if you have to require too many scripts) or in another script that would then be called in the main lua.  With the sample quest, I believe there is a script called features.lua that fills this purpose. It collects many scripts into one and then is required at the beginning of the main.lua.

so at the top of your main.lua you should type this:

--- Code: ---require("scripts/game")  --If you saved it in the scripts folder. require("scripts/meta/game") if you added the subfolder.

--- End code ---

unless you compile many of your scripts into one feature script; which is recommended.

Hope this helps.

CopperKatana:
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.


--- Code: ---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)

--- End code ---

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):


--- Code: ----- 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!

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version