Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Christopho

Pages: 1 ... 77 78 [79]
1171
Development / 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.
end

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

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.

1172
Thanks for your suggestions.
I renamed Game art to Game art & music, and I changed the description of Development to something clearer and more general.
Since the forum is new and quite empty for now, I don't want to make a lot of boards for now.

1173
TL;DR
Chapters 1 to 5 of http://www.lua.org/pil/contents.html

That's a very good question.
Like always in programming, it is better not to start directly by writing code, but learning and using Lua is easy.

Lua is very minimalist but powerful. There are only a few mechanisms to learn (variables, functions, table, metatables), everything is built using these base mechanisms.

To learn Lua, the best way is to buy the Programming in Lua book in its latest edition. It is the recommended book.

But you can also read the online version of the first edition of that book, it is free: http://www.lua.org/pil/contents.html
I recommend to read chapters 1 to 5, then you know enough to make scripts for Solarus. Later, you should also read chapters 11, 13, 16, 18, 19, 20 to understand what you are doing.

I should make a page or a PDF sheet that summarizes the main features of Lua, on the documentation or the wiki. Especially the ones that are important for Solarus:
- Variables should be declared local unless you know what you are doing.
- Functions are first-class values. The definition of a function is actually an assignment (to a variable or to a table field).
- Tables are the only data structure.
- The semicolon operator is syntaxic sugar to hide the first parameter of a function.
- A Lua script file is a regular function and can take parameters with the syntax ... (3 dots).

1174
General discussion / Re: Welcome!
« on: August 07, 2013, 07:07:12 am »
There is already the "Development" board for that. :)
Maybe I should change the description?

1175
Bugs & Feature requests / Re: Video Tutorials
« on: August 05, 2013, 05:00:56 pm »
Actually I started a video tutorial series just a few days ago, but it is in French :P

If someone who understands French and speaks English better than me, a nice thing would be to make an English version of each video :)
Either by reproducing the same steps, or by using the same video track but with your voice instead of mine. (I can make the video without voice but with the music available for download.)

1176
General discussion / Re: bug
« on: August 05, 2013, 04:58:05 pm »
Oops :)
It's fixed now. Thanks

1177
General discussion / Welcome!
« on: August 05, 2013, 02:31:00 pm »
Since the Solarus 1.0 release, several people suggested to create a forum to talk about game development with Solarus, get help, share scripts and game resources.
So that's done! Feel free to make any suggestion.
Welcome everybody!

Pages: 1 ... 77 78 [79]