Skip to content

Commit 87f3943

Browse files
committed
the 'collider' editor now snaps to half-pixel resolution
1 parent 2f88cd6 commit 87f3943

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
<!-- next-header -->
22
## [Unreleased] - ReleaseDate
33

4+
### Improved
5+
6+
- The `collider` (example) editor now snaps to half-pixels.
7+
48
## [5.2.0] - 2022-09-13
59

6-
## Added
10+
### Added
711

812
- Added `KeyboardStateChain` and `MouseStateChain` to provide a functional interface for dealing with user input. Call `.chain()` on `KeyboardState` or `MouseState` to access them. These new structs have methods with the same names as in their `Chain`-less variants which accept closures to perform the logic, and can be chained. Contributed by [@just-do-halee](https://github.com/just-do-halee) in [#55].
913

10-
## Improved
14+
### Improved
1115

1216
- `CollisionPair` now implements `IntoIterator`, so you can do, for example: `for label in event.pair { ... }`. Contributed by [@just-do-halee](https://github.com/just-do-halee) in [#55].
1317

1418
[#55]: https://github.com/CleanCut/rusty_engine/pull/55
1519

1620
## [5.1.1] - 2022-08-01
1721

18-
## Improved
22+
### Improved
1923

2024
- Updated to `bevy 0.8` and `bevy_prototype_lyon 0.6` under the hood, which resolves the occasional stuttering problem.
2125

examples/collider.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ use rusty_engine::prelude::*;
1818

1919
struct GameState {
2020
circle_radius: f32,
21+
scale: f32,
2122
}
2223

2324
impl Default for GameState {
2425
fn default() -> Self {
2526
Self {
2627
circle_radius: 16.0,
28+
scale: 1.0,
2729
}
2830
}
2931
}
@@ -96,35 +98,38 @@ fn main() {
9698
}
9799

98100
fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
99-
let sprite = engine.sprites.get_mut("sprite").unwrap();
100101
// Zoom levels
101102
if engine.keyboard_state.just_pressed(KeyCode::Key1) {
102-
sprite.scale = 1.0;
103+
game_state.scale = 1.0;
103104
}
104105
if engine.keyboard_state.just_pressed(KeyCode::Key2) {
105-
sprite.scale = 2.0;
106+
game_state.scale = 2.0;
106107
}
107108
if engine.keyboard_state.just_pressed(KeyCode::Key3) {
108-
sprite.scale = 3.0;
109+
game_state.scale = 3.0;
109110
}
110111
if engine.keyboard_state.just_pressed(KeyCode::Key4) {
111-
sprite.scale = 4.0;
112+
game_state.scale = 4.0;
112113
}
113114
if engine.keyboard_state.just_pressed(KeyCode::Key5) {
114-
sprite.scale = 5.0;
115+
game_state.scale = 5.0;
115116
}
116117
if engine.keyboard_state.just_pressed(KeyCode::Key6) {
117-
sprite.scale = 6.0;
118+
game_state.scale = 6.0;
118119
}
119120
if engine.keyboard_state.just_pressed(KeyCode::Key7) {
120-
sprite.scale = 7.0;
121+
game_state.scale = 7.0;
121122
}
122123
if engine.keyboard_state.just_pressed(KeyCode::Key8) {
123-
sprite.scale = 8.0;
124+
game_state.scale = 8.0;
124125
}
125126
if engine.keyboard_state.just_pressed(KeyCode::Key9) {
126-
sprite.scale = 9.0;
127+
game_state.scale = 9.0;
127128
}
129+
// Update scale
130+
let sprite = engine.sprites.get_mut("sprite").unwrap();
131+
sprite.scale = game_state.scale;
132+
128133
// Rotate
129134
if engine.mouse_state.pressed(MouseButton::Right) {
130135
sprite.rotation += engine.delta_f32 * 6.0;
@@ -139,6 +144,7 @@ fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
139144
// Modify a collider point
140145
if engine.mouse_state.just_pressed(MouseButton::Left) {
141146
if let Some(location) = engine.mouse_state.location() {
147+
let location = (((location / game_state.scale) * 2.0).round() * 0.5) * game_state.scale;
142148
if engine
143149
.keyboard_state
144150
.pressed_any(&[KeyCode::RShift, KeyCode::LShift])

0 commit comments

Comments
 (0)