|
8 | 8 | //! [](https://play.c7.se/ff/fp8x8/) |
9 | 9 | //! [](https://play.c7.se/ff/rng/) |
10 | 10 | //! |
11 | | -//! #### You might want to install the [ff-init](https://github.com/peterhellberg/ff-init) tool and use that instead of manually creating the files for your game. |
| 11 | +//! #### You might want to install [ff-init](https://github.com/peterhellberg/ff-init) ✨ |
| 12 | +//! |
| 13 | +//! _(and use that instead of manually creating the files for your game)_ |
| 14 | +//! |
| 15 | +//! ##### Installation |
| 16 | +//! |
| 17 | +//! _(Requires you to have [Go](https://go.dev/dl/) installed)_ |
| 18 | +//! |
| 19 | +//! ``` |
| 20 | +//! go install github.com/peterhellberg/ff-init@latest |
| 21 | +//! ``` |
| 22 | +//! |
| 23 | +//! ##### Usage |
| 24 | +//! |
| 25 | +//! _(Requires you to have a recent version of |
| 26 | +//! [Zig](https://ziglang.org/download/#release-master), |
| 27 | +//! [firefly_cli](https://docs.fireflyzero.com/user/installation/#-cli), and the |
| 28 | +//! [firefly-emulator](https://docs.fireflyzero.com/user/installation/#-emulator) |
| 29 | +//! installed)_ |
| 30 | +//! |
| 31 | +//! ``` |
| 32 | +//! ff-init myapp |
| 33 | +//! cd myapp |
| 34 | +//! zig build run |
| 35 | +//! ``` |
| 36 | +//! 🌱 |
| 37 | +//! |
| 38 | +//! |
| 39 | +//! ## Callbacks |
| 40 | +//! |
| 41 | +//! You often only _need_ to export the **`update`** and **`render`** functions, |
| 42 | +//! but there are a number of other [callbacks](https://docs.fireflyzero.com/dev/callbacks/) |
| 43 | +//! you can use as appropriate. |
| 44 | +//! |
| 45 | +//! **The available callbacks are:** |
| 46 | +//! |
| 47 | +//! - ### **`boot`** |
| 48 | +//! > _Called only once, **after** all the memory is initialized and all runtime functions are |
| 49 | +//! available but before any other callback is called. This is the best place to load |
| 50 | +//! fonts, sprites, and other assets, initialize the default state, read configurations, etc._ |
| 51 | +//! |
| 52 | +//! ``` |
| 53 | +//! pub export fn boot() void {} |
| 54 | +//! ``` |
| 55 | +//! |
| 56 | +//! - ### **`update`** |
| 57 | +//! > _Called **~60** times per second. It is guaranteed to be never called more often, |
| 58 | +//! and it won’t be called less often if the game doesn’t consume too much resources. |
| 59 | +//! This is the best place to update the state of objects, position of NPCs, read and |
| 60 | +//! handle user input, etc._ |
| 61 | +//! |
| 62 | +//! ``` |
| 63 | +//! pub export fn update() void {} |
| 64 | +//! ``` |
| 65 | +//! |
| 66 | +//! - ### **`render`** |
| 67 | +//! > _Called **before** updating the image on the screen. It might be called less often |
| 68 | +//! than `update` if the device sees that the game is slow and needs more resources. |
| 69 | +//! This is the best place to call all drawing functions._ |
| 70 | +//! |
| 71 | +//! ``` |
| 72 | +//! pub export fn render() void {} |
| 73 | +//! ``` |
| 74 | +//! |
| 75 | +//! - ### **`render_line`** |
| 76 | +//! > _Called **before** updating a line of pixels on the screen. It accepts the line for |
| 77 | +//! each it is called and returns the next line before which it should be called again. |
| 78 | +//! For example, it is called with 0 first time and if it then returns 100, |
| 79 | +//! it will be called again before rendering the line 100. If then it returns 0, |
| 80 | +//! it will be called again only when rendering the next frame. Use it to update |
| 81 | +//! the color palette on the fly if you want to display more than 16 colors on one frame._ |
| 82 | +//! |
| 83 | +//! **(It seems like this callback might not work as it should in the emulator just yet)** |
| 84 | +//! |
| 85 | +//! ``` |
| 86 | +//! pub export fn render_line(l: i32) i32 { |
| 87 | +//! return 0; |
| 88 | +//! } |
| 89 | +//! ``` |
| 90 | +//! |
| 91 | +//! - ### **`before_exit`** |
| 92 | +//! > _Called **before** the app is closed._ |
| 93 | +//! |
| 94 | +//! ``` |
| 95 | +//! pub export fn before_exit() void {} |
| 96 | +//! ``` |
12 | 97 | //! |
13 | 98 |
|
14 | 99 | const std = @import("std"); |
|
0 commit comments