Skip to content

Commit

Permalink
Add debug demo, make objects visible in ortho map
Browse files Browse the repository at this point in the history
Default points to 1.0 size objects, for fallback and visibility
  • Loading branch information
dmtaub committed Mar 15, 2021
1 parent 4f90abc commit a82aebb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets/ortho-map.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
eJzVl9lNw0AURZ8ltgr4YquAjliaYPl8DdAChCVABRB2KkBhpwK2sKQC4FgiShQ8tseMx/aVjmRLY+fO3JnnFxGRGZiVamkBFos2EaOBQGQw6N6PFmcltcbwOx50vU+neKYztsb1OmzAZq4uo9XxbjO2wfUBHMJRjt5c6RyacAlXcF2oGzu9wCu0YCohpwcPftJqFdZ+r9uGMf1nvWjtwX7P/UiEN5vzUiZRW5Qao9QarUHRftKI2qLUGKXWaCOjZ9/zprYoNUapNdrM+Hsu5m0jaotSY5Rao62M73Ax70d4gme4yOgjSb01tH/eu/947xd8izvfS7Ds6F2+VZP8e5oVx+8rY0/D90dN385QPnuapN7DZnxvT1O2HiCNqtYD2GaXt3aot9tQh62K9CJn+DyFEziuiOd7fN7BLdyUxDN5C7kL+Yf74I8+8fkB7/AGQ+zdYU/7t21YI/IWchfyD/dBoibwO1nwmSNvIXch/3AfxCopE18ibyF3If9wH8TKNhOfMq2nTSZ5yXSeTOvZn0nU83Mw78Bb1P/tUKbzlHY9k87jD20Li3Y=
</data>
</layer>
<objectgroup id="3" name="Objects" visible="0">
<objectgroup id="3" name="Objects">
<object id="1" name="maggots" type="location" x="435" y="74" width="155" height="99">
<properties>
<property name="spawncount" type="int" value="5"/>
Expand Down
43 changes: 43 additions & 0 deletions examples/ortho_objects.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use bevy::prelude::*;
use bevy_tiled_prototype::{DebugConfig, Object, TiledMapCenter};

// this example demonstrates debugging objects

const SCALE: f32 = 2.0;

fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_plugin(bevy_tiled_prototype::TiledMapPlugin)
.add_system(bevy::input::system::exit_on_esc_system.system())
.add_system(toggle_debug.system())
.add_startup_system(setup.system())
.run();
}

fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
commands
.spawn(bevy_tiled_prototype::TiledMapComponents {
map_asset: asset_server.load("ortho-map.tmx"),
center: TiledMapCenter(true),
origin: Transform::from_scale(Vec3::new(SCALE, SCALE, 1.0)),
debug_config: DebugConfig {
enabled: true,
material: None,

},
..Default::default()
})
.spawn(Camera2dBundle::default());
}

fn toggle_debug(
keyboard_input: Res<Input<KeyCode>>,
mut query: Query<&mut Visible, With<Object>>,
) {
for mut visible in query.iter_mut() {
if keyboard_input.just_released(KeyCode::Space) {
visible.is_visible = !visible.is_visible;
}
}
}
2 changes: 1 addition & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl Object {
tiled::ObjectShape::Ellipse { width , height } => Some(Vec2::new(width, height)),
tiled::ObjectShape::Polyline { points: _ } |
tiled::ObjectShape::Polygon { points: _ } |
tiled::ObjectShape::Point(_, _) => None,
tiled::ObjectShape::Point(_, _) => Some(Vec::splat(1.0)),
}
}
}
Expand Down

0 comments on commit a82aebb

Please sign in to comment.