diff --git a/tiled/src/lib.rs b/tiled/src/lib.rs
index c3e7fcd4..cb02cace 100644
--- a/tiled/src/lib.rs
+++ b/tiled/src/lib.rs
@@ -114,11 +114,14 @@ impl Default for TileFlippedParams {
}
impl Map {
- pub fn spr(&self, tileset: &str, sprite: u32, dest: Rect) {
- self.spr_flip(tileset, sprite, dest, TileFlippedParams::default())
- }
-
- pub fn spr_flip(&self, tileset: &str, sprite: u32, dest: Rect, flip: TileFlippedParams) {
+ pub fn spr_flip_with(
+ &self,
+ tileset: &str,
+ sprite: u32,
+ dest: Rect,
+ flip: TileFlippedParams,
+ draw_func: impl FnOnce(&Texture2D, f32, f32, Color, DrawTextureParams),
+ ) {
if self.tilesets.contains_key(tileset) == false {
panic!(
"No such tileset: {}, tilesets available: {:?}",
@@ -136,7 +139,7 @@ impl Map {
0.0
};
- draw_texture_ex(
+ draw_func(
&tileset.texture,
dest.x,
dest.y,
@@ -156,11 +159,30 @@ impl Map {
},
);
}
+ pub fn spr(&self, tileset: &str, sprite: u32, dest: Rect) {
+ self.spr_flip_with(
+ tileset,
+ sprite,
+ dest,
+ TileFlippedParams::default(),
+ draw_texture_ex,
+ )
+ }
- pub fn spr_ex(&self, tileset: &str, source: Rect, dest: Rect) {
+ pub fn spr_flip(&self, tileset: &str, sprite: u32, dest: Rect, flip: TileFlippedParams) {
+ self.spr_flip_with(tileset, sprite, dest, flip, draw_texture_ex);
+ }
+
+ pub fn spr_ex_with(
+ &self,
+ tileset: &str,
+ source: Rect,
+ dest: Rect,
+ draw_func: impl FnOnce(&Texture2D, f32, f32, Color, DrawTextureParams),
+ ) {
let tileset = &self.tilesets[tileset];
- draw_texture_ex(
+ draw_func(
&tileset.texture,
dest.x,
dest.y,
@@ -172,12 +194,20 @@ impl Map {
},
);
}
+ pub fn spr_ex(&self, tileset: &str, source: Rect, dest: Rect) {
+ self.spr_ex_with(tileset, source, dest, draw_texture_ex);
+ }
pub fn contains_layer(&self, layer: &str) -> bool {
self.layers.contains_key(layer)
}
-
- pub fn draw_tiles(&self, layer: &str, dest: Rect, source: impl Into