Skip to content

Commit 51e28da

Browse files
authored
Merge pull request #38 from CleanCut/placement
Use 'placement' instead of 'transform'
2 parents 015f345 + 6b54a46 commit 51e28da

File tree

10 files changed

+19
-19
lines changed

10 files changed

+19
-19
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! To run this code, clone the rusty_engine repository and run the command:
22
//!
3-
//! cargo run --release --example transform
3+
//! cargo run --release --example placement
44
55
use rusty_engine::prelude::*;
66

scenarios/car_shoot.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ In your `// game setup goes here` section of `main`...
4949
In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-game-logic-function.html)...
5050

5151
1. Have the "gun barrel" follow the mouse on the X axis by set the `translation.x` of the player sprite to the `x` value of the mouse location.
52-
- Get a [mutable reference to the player sprite](https://cleancut.github.io/rusty_engine/60-sprite-transform.html#adjusting-an-existing-sprite)
52+
- Get a [mutable reference to the player sprite](https://cleancut.github.io/rusty_engine/60-sprite-placement.html#adjusting-an-existing-sprite)
5353
- Get the mouse location via the [mouse state's `location` method](https://cleancut.github.io/rusty_engine/115-mouse-state.html#location)
5454
- Make a variable `player_x` and set it to the player's current `translation.x` so we can use it later on: `let player_x = player.translation.x;`
5555

@@ -79,7 +79,7 @@ In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-
7979
1. For every sprite [value in the hash map](https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.values):
8080
- check to see if either the `translation.y > 400.0` or the `translation.x > 750.0`. If either of those conditions are true, push a clone of the label onto the `labels_to_delete` vector.
8181
1. For every label in `labels_to_delete`:
82-
- [Remove the sprite entry.](https://cleancut.github.io/rusty_engine/60-sprite-transform.html#deleting-a-sprite) The hash map's `remove` method takes an immutable reference to the key type, so if you are looping through the label strings by value, you may need to add a `&` in front of your label variable: `engine.sprites.remove(&label)`
82+
- [Remove the sprite entry.](https://cleancut.github.io/rusty_engine/60-sprite-placement.html#deleting-a-sprite) The hash map's `remove` method takes an immutable reference to the key type, so if you are looping through the label strings by value, you may need to add a `&` in front of your label variable: `engine.sprites.remove(&label)`
8383
1. Spawn a car if the `game_state.spawn_timer` just finished! So [tick the spawn timer and check to see if it just finished](https://cleancut.github.io/rusty_engine/250-timer.html#counting-down--finishing) -- if it did, then:
8484
1. Set `game_state.spawn_timer` to a new `Timer` with a random value between `0.1` and `1.25`
8585
- Add the `rand` crate as a dependency in your `Cargo.toml`
@@ -88,7 +88,7 @@ In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-
8888
- [Create a non-repeating `Timer`](https://cleancut.github.io/rusty_engine/250-timer.html#creation) and assign it as the value to `game_state.spawn_timer`
8989
1. If there are any cars left (check the value of `game_state.cars_left`), then:
9090
1. Decrement `game_state.cars_left` by one
91-
1. [Retrieve a mutable reference to the](https://cleancut.github.io/rusty_engine/165-text-transform.html#adjusting-an-existing-text) `Text` we labeled `"cars left"`
91+
1. [Retrieve a mutable reference to the](https://cleancut.github.io/rusty_engine/165-text-placement.html#adjusting-an-existing-text) `Text` we labeled `"cars left"`
9292
- Set the `value` to `format!("Cars left: {}", game_state.cars_left)`
9393
1. Create a label for the current car that starts with `car`: `format!("car{}", game_state.cars_left)` (remember, a label starting with `car` is what the movement code is looking for).
9494
1. Create a vector of `SpritePreset`s of cars to randomly select from: `let car_choices = vec![SpritePreset::RacingCarBlack, SpritePreset::RacingCarBlue, SpritePreset::RacingCarGreen, SpritePreset::RacingCarRed, SpritePreset::RacingCarYellow];`
@@ -100,7 +100,7 @@ In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-
100100
1. Now it's time to handle the collisions! For each [`CollisionEvent`](https://docs.rs/rusty_engine/latest/rusty_engine/physics/struct.CollisionEvent.html) in `engine.collision_events`:
101101
- We only care about the start of collisions, not the ending of them, so if `event.state.is_end()`, then `continue` the loop.
102102
- Similarly, if one of the event pair's labels _doesn't_ start with `"marble"`, then it's either two marbles or two cars colliding with each other, which we don't care about. So if `!event.pair.one_starts_with("marble")`, then `continue` the loop.
103-
- At this point we know that one of the pair is a marble and the other is a car, and they both need to be removed. So using the labels in the `event.pair` tuple, [delete both sprites](https://cleancut.github.io/rusty_engine/60-sprite-transform.html#deleting-a-sprite).
103+
- At this point we know that one of the pair is a marble and the other is a car, and they both need to be removed. So using the labels in the `event.pair` tuple, [delete both sprites](https://cleancut.github.io/rusty_engine/60-sprite-placement.html#deleting-a-sprite).
104104
- Now that a marble has been "destroyed", we are allowed to shoot it from the gun again, so grab whichever label of the `event.pair` tuple that starts with `"marble"` and [push](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.push) a clone of it back onto the `game_state.marbles_left` vector.
105105
- [Play a sound effect](https://cleancut.github.io/rusty_engine/210-sfx.html#play) for successfully hitting a car with a marble. Use `SfxPreset::Confirmation1` with a volume of `0.5`
106106

scenarios/road_race.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In your `// game setup goes here` section of `main()`...
3636
1. Create a sprite using the [`.add_sprite()`](https://cleancut.github.io/rusty_engine/55-sprite-creation.html) method of `Game` (`.add_sprite()` returns a mutable reference to the sprite you can use to access its fields)
3737
1. Label it `"player1"`
3838
1. Use the preset `SpritePreset::RacingCarBlue`
39-
1. Set the following [attributes](https://cleancut.github.io/rusty_engine/60-sprite-transform.html) on the `player1` sprite via the mutable reference:
39+
1. Set the following [attributes](https://cleancut.github.io/rusty_engine/60-sprite-placement.html) on the `player1` sprite via the mutable reference:
4040
1. Set `translation.x` to `-500.0` so the car will be near the left side of the screen
4141
1. Set the player sprite's `layer` to `10.0` so it will be on top of other sprites by default (higher layers are rendered on top of lower layers)
4242
1. Set the player sprite's `collision` to `true` so that `player1` will detect collisions with other sprites.

src/physics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl Collider {
275275
rotated_points
276276
}
277277
#[doc(hidden)]
278-
// Used internally to scale colliders to match a sprite's current transform
278+
// Used internally to scale colliders to match a sprite's current translation, rotation, and scale
279279
pub fn relative_to(&self, sprite: &Sprite) -> Vec<Vec2> {
280280
self.rotated(sprite.rotation)
281281
.iter()

src/sprite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Sprite {
8787
}
8888
}
8989

90-
/// Do the math to translate from Rusty Engine translation+rotation+scale to Bevy's Transform
90+
/// Do the math to convert from Rusty Engine translation+rotation+scale+layer to Bevy's Transform
9191
#[doc(hidden)]
9292
pub fn bevy_transform(&self) -> Transform {
9393
let mut transform = Transform::from_translation(self.translation.extend(self.layer));

tutorial/src/115-mouse-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if engine.mouse_state.just_released_any(&[MouseButton::Left, MouseButton::Middle
3737

3838
### Location
3939

40-
Use the `location` method to see where the mouse is. It returns an `Option<Vec2>`. If `None` is returned, then the mouse pointer isn't in the window. If present, the `Vec2` value is in the same 2D world coordinate system as the rest of the game. See the [section on sprite translation](60-sprite-transform.html) for more info about `Vec2` or the world coordinate system.
40+
Use the `location` method to see where the mouse is. It returns an `Option<Vec2>`. If `None` is returned, then the mouse pointer isn't in the window. If present, the `Vec2` value is in the same 2D world coordinate system as the rest of the game. See the [section on sprite translation](60-sprite-placement.html) for more info about `Vec2` or the world coordinate system.
4141

4242
It is easy to demonstrate `location` by having a sprite appear wherever your mouse is located:
4343

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Text Transform
1+
# Text Placement
22

3-
Text is rendered as an image. This rendering (or re-rendering) happens at the end of the frame after any of the [Value, Font & Font Size](160-text-attributes.md) attributes are changed. However, when _transform_ values such as translation, rotation, scale, or layer are changed, the image remains the same and its representation on screen is manipulated in the GPU, which is high performance.
3+
Text is rendered as an image. This rendering (or re-rendering) happens at the end of the frame after any of the [Value, Font & Font Size](160-text-attributes.md) attributes are changed. However, when values such as translation, rotation, scale, or layer are changed, the image remains the same and its representation on screen is manipulated in the GPU, which is high performance.
44

5-
In short, feel free to change your text's transform attributes every frame without any big hit in performance.
5+
In short, feel free to change your text's placement attributes every frame without any big hit in performance.
66

77
### Translation
88

@@ -32,7 +32,7 @@ score_text.rotation = std::f32::consts::PI / 4.0;
3232

3333
Usually, you will want to leave text at a scale of `1.0`, but if you wish to have text zoom or shrink, modifying the scale has two important advantages compared to changing the font size:
3434

35-
- Changing the scale is _fast_. The text image does not need to be re-rendered, and the size transformation is handled all in GPU hardware.
35+
- Changing the scale is _fast_. The text image does not need to be re-rendered, and the size change is handled all in GPU hardware.
3636
- Changing the scale doesn't cause weird re-rendering inconsistencies, so animating scale changes looks smooth.
3737

3838
The main drawback of changing the scale is that since the font is not re-rendered, it looks pixellated when scaled up. Though, this could be considered as a stylistic plus as well.
@@ -73,7 +73,7 @@ text.translation.x = 0.0;
7373
player.translation.y = -300.0;
7474
```
7575

76-
NOTE: If you want to adjust your text's transform smoothly, you will need to multiply your change by the frame's delta value. See the [`Engine`](400-engine.md) section for more details.
76+
NOTE: If you want to adjust your text's placement smoothly, you will need to multiply your change by the frame's delta value. See the [`Engine`](400-engine.md) section for more details.
7777

7878
### Adjusting an existing text
7979

tutorial/src/50-sprite.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sprite
22

3-
A _sprite_ in Rusty Engine is a 2D image, its transform (translation, rotation, scale), its collider, and other associated metadata. You will use sprites for all the graphics in your game. Many sprites will represent some _thing_. For example, a race car sprite may represent your player character in your game.
3+
A _sprite_ in Rusty Engine is a 2D image, how it is placed on the screen (translation, rotation, scale, and layer), its collider, and other associated metadata. You will use sprites for all the graphics in your game. Many sprites will represent some _thing_. For example, a race car sprite may represent your player character in your game.
44

55
![green race car sprite](https://github.com/CleanCut/rusty_engine/raw/main/assets/sprite/racing/car_green.png)
66

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Transform
1+
# Sprite Placement
22

3-
A "transform" is a fancy term for the way that you can position and size your sprite. There are four different fields you can use to position and size your sprite:
3+
There are four different fields you can use to position and size your sprite:
44

55
### Translation
66

tutorial/src/SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- [Game Logic Function](25-game-logic-function.md)
1313
- [Sprite](50-sprite.md)
1414
- [Creation](55-sprite-creation.md)
15-
- [Transform](60-sprite-transform.md)
15+
- [Placement](60-sprite-placement.md)
1616
- [Collider](65-sprite-collider.md)
1717
- [Input](100-input.md)
1818
- [Keyboard State](105-keyboard-state.md)
@@ -22,7 +22,7 @@
2222
- [Text](150-text.md)
2323
- [Creation](155-text-creation.md)
2424
- [Value, Font & Font Size](160-text-attributes.md)
25-
- [Transform](165-text-transform.md)
25+
- [Placement](165-text-placement.md)
2626
- [Audio](200-audio.md)
2727
- [Music](205-music.md)
2828
- [Sound Effects](210-sfx.md)

0 commit comments

Comments
 (0)