-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New renderer #62
base: main
Are you sure you want to change the base?
New renderer #62
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ https://www.mapeditor.org/ | |
|
||
Feel free to use this code as a reference for your own custom tile mapping solution as well. | ||
|
||
This plugin uses bevy_ecs_tilemap(https://github.com/StarArawn/bevy_ecs_tilemap) to render tiled data. | ||
|
||
## Bevy Versions | ||
|
||
The `main` branch of this repository targets Bevy 0.5. When using bevy_tiled, please make sure your version of Bevy matches the version referenced by this library. There are versions for 0.4 and 0.3 as well. | ||
|
@@ -37,13 +39,16 @@ In these examples, you should be able to use the wasd keys to pan across the map | |
# Features | ||
## Toplevel Entity Support | ||
|
||
TODO: REWRITE THIS SECTION | ||
For now, TiledMapBundle is just a configuration object. If you would like access to a toplevel entity that can be transformed, pass into the configuration: | ||
|
||
parent_option: Some(entity) | ||
|
||
Then, both chunks and objects will be inserted as children to this entity, which will be tagged with MapRoot. This API is likely to change, but we have an [example](/examples/parent_entity.rs) for how it currently works. | ||
## Object Group Support | ||
|
||
TODO: REWRITE THIS SECTION | ||
|
||
Object Grous are now supported. They will be skipped if not visible. Individual objects that are invisible | ||
will be spawned with is_visible set to false. You may pass into the configuration object: | ||
|
||
|
@@ -83,11 +88,13 @@ Then when you save your map, it should update in the application. | |
|
||
## WASM and bevy_webgl2 | ||
|
||
## TODO see if web still works? :/ | ||
|
||
Use `default-features=false, features=["web"]` in your project's `Cargo.toml`. Tiled maps using Zstd compression are not supported. | ||
|
||
## Top-needed features | ||
|
||
* better support for isometric maps | ||
* support for embeded objects in tiles | ||
* support for embedded images in Tmx files | ||
* support for animations | ||
* ~~support for animations~~ done | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still needed for objects |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod texture_sampler; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use bevy::{prelude::*, render::texture::FilterMode}; | ||
|
||
// demo of https://github.com/StarArawn/bevy_tiled/issues/47#issuecomment-817126515 | ||
// Would be cleaner to put this in a separate AppState, transitioning out after textures loaded | ||
pub fn set_texture_filters_to_nearest( | ||
mut texture_events: EventReader<AssetEvent<Texture>>, | ||
mut textures: ResMut<Assets<Texture>>, | ||
) { | ||
// quick and dirty, run this for all textures every time a map is created/modified | ||
for event in texture_events.iter() { | ||
match event { | ||
AssetEvent::Created { handle } => { | ||
if let Some(mut texture) = textures.get_mut(handle){ | ||
texture.sampler.min_filter = FilterMode::Nearest; | ||
} | ||
Comment on lines
+8
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're going through all the trouble to do this in every example, should we consider enabling it as a feature or with a boolean flag in a config object? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could have a feature that queries textures for the tiled map layers and updates them to use min_filter. I think having the user do this during a "loading" game state is probably better though. |
||
} | ||
_ => () | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use bevy::prelude::*; | ||
use bevy_ecs_tilemap::prelude::Tile; | ||
|
||
/// Information specific to the current frame in the animation. | ||
#[derive(Clone)] | ||
pub struct Frame { | ||
/// Tile id. | ||
pub tile_id: u32, | ||
/// Duration until next frame. | ||
pub duration: f64, | ||
} | ||
|
||
/// Information about the tiles animation state. | ||
pub struct Animation { | ||
/// Frame info. | ||
pub frames: Vec<Frame>, | ||
/// The current frame. | ||
pub current_frame: usize, | ||
pub last_update: f64, | ||
} | ||
|
||
pub fn update( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
time: Res<Time>, | ||
mut query: Query<(&mut Tile, &mut Animation)>, | ||
) { | ||
let current_time = time.seconds_since_startup(); | ||
for (mut tile, mut animation) in query.iter_mut() { | ||
let frame = animation.frames[animation.current_frame].clone(); | ||
if (current_time - animation.last_update) > frame.duration { | ||
animation.current_frame += 1; | ||
tile.texture_index = frame.tile_id; | ||
if animation.current_frame > animation.frames.len() - 1 { | ||
animation.current_frame = 0; | ||
} | ||
animation.last_update = current_time; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rparrett if you have a chance to try it out -- I'd be interested to know whether this new render can be adapted for use on web...