Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Commit

Permalink
Merge #1132
Browse files Browse the repository at this point in the history
1132: move spritesheet definition to next chapter r=LucioFranco a=qqwa



Co-authored-by: Benjamin Bäumler <benjamin.baeumler@qqwa.de>
  • Loading branch information
bors[bot] and qqwa committed Nov 14, 2018
2 parents 47c5f78 + f612b7d commit d4b94c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
29 changes: 0 additions & 29 deletions book/src/pong-tutorial/pong-tutorial-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,34 +179,6 @@ Then we call `.run()` on `game` which begins the gameloop. The game will
continue to run until our `State` returns `Trans::Quit`, or when all states have
been popped off the state machine's stack.

Finally, let's create a `texture` folder in the root of the project. This
will contain the [spritesheet texture][ss] `pong_spritesheet.png` we will need
to render the elements of the game. To go with it, we need a file describing
where the sprites are on the sheet. Let's create, right next to it, a file
called `pong_spritesheet.ron`. It will contain the following sprite sheet
definition:

```text,ignore
(
spritesheet_width: 8.0,
spritesheet_height: 16.0,
sprites: [
(
x: 0.0,
y: 0.0,
width: 4.0,
height: 16.0,
),
(
x: 4.0,
y: 0.0,
width: 4.0,
height: 4.0,
),
],
)
```

Success! Now we should be able to compile and run this code and get a window.
It should look something like this:

Expand All @@ -216,4 +188,3 @@ It should look something like this:
[st]: https://www.amethyst.rs/doc/master/doc/amethyst/trait.State.html
[ap]: https://www.amethyst.rs/doc/master/doc/amethyst/struct.Application.html
[gs]: ../getting-started.html
[ss]: ../images/pong_tutorial/pong_spritesheet.png
34 changes: 31 additions & 3 deletions book/src/pong-tutorial/pong-tutorial-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,10 @@ Hooray!
This section will finally allow us to see something.

The first thing we will have to do is load the sprite sheet we will use for all
our graphics in the game. Here, it is located in `texture/pong_spritesheet.png`.
We will perform the loading in a new function in `pong.rs` called `load_sprite_sheet`.
our graphics in the game. Create a `texture` folder in the root of the project.
This will contain the [spritesheet texture][ss] `pong_spritesheet.png` we will
need to render the elements of the game. We will perform the loading in a new
function in `pong.rs` called `load_sprite_sheet`.

First, let's declare the function and load the spritesheet's image.

Expand Down Expand Up @@ -456,7 +458,32 @@ This handle "points" to the place where the asset will be loaded. In Rust terms,
equivalent to a reference-counted option. It is extremely useful, especially as cloning
the handle does not clone the asset in memory, so many things can use the same asset at once.

Finally, we load the file containing the position of each sprites on the sheet.
Alongside our spritesheet texture, we need a file describing where the sprites
are on the sheet. Let's create, right next to it, a file called
`pong_spritesheet.ron`. It will contain the following sprite sheet definition:

```text,ignore
(
spritesheet_width: 8.0,
spritesheet_height: 16.0,
sprites: [
(
x: 0.0,
y: 0.0,
width: 4.0,
height: 16.0,
),
(
x: 4.0,
y: 0.0,
width: 4.0,
height: 4.0,
),
],
)
```

Finally, we load the file containing the position of each sprite on the sheet.

```rust,no_run,noplaypen
# extern crate amethyst;
Expand Down Expand Up @@ -617,3 +644,4 @@ moving!
[sb]: https://slide-rs.github.io/specs/
[sb-storage]: https://slide-rs.github.io/specs/05_storages.html#densevecstorage
[2d]: https://www.amethyst.rs/doc/master/doc/amethyst_renderer/struct.Camera.html#method.standard_2d
[ss]: ../images/pong_tutorial/pong_spritesheet.png

0 comments on commit d4b94c7

Please sign in to comment.