7 个版本 (破坏性更新)
0.8.0 | 2023年7月22日 |
---|---|
0.7.0 | 2023年4月12日 |
0.6.0 | 2022年11月14日 |
0.5.0 | 2022年9月26日 |
0.2.0 | 2022年1月6日 |
在 游戏开发 中排名 1843
每月下载量 51
在 3 个 工具包中使用(2 个直接使用)
28KB
494 行
bevy_tileset
使用 RON 在 Bevy 中创建简单、可配置的瓦片集。
所有 GIF 都使用
bevy_tileset_map
工具包生成
📋 功能
- 通过 RON 文件定义瓦片集和瓦片
- 直接将瓦片集作为 Bevy 资产加载
- 定义标准、动画、变体和自动瓦片
📲 安装
将以下任一行添加到您的 Cargo.toml
。
[dependencies]
bevy_tileset_tiles = "0.8" # For the base tile definitions
bevy_tileset = "0.8" # For general tileset usage (includes above)
✨ 使用
简单地在配置文件中定义您的瓦片和瓦片集
// assets/tiles/my_tile.ron
(
name: "My Tile",
tile: Standard("textures/my_tile.png")
)
// assets/my_tileset.ron
(
name: Some("My Awesome Tileset"),
id: 0,
tiles: {
0: "../tiles/my_tile.ron",
// ...
}
)
并通过系统加载它
use bevy::prelude::*;
use bevy_tileset::prelude::*;
fn load_tiles(asset_server: Res<AssetServer>) {
let handle: Handle<Tileset> = asset_server.load("my_tileset.ron");
// Store handle...
}
然后从任何地方访问生成的瓦片集
fn my_system(tilesets: Tilesets, /* other system params */) {
let tileset = tilesets.get_by_name("My Awesome Tileset").unwrap();
let tile_index = tileset.get_tile_index("My Tile").unwrap();
match tile_index {
TileIndex::Standard(texture_index) => { /* Do something */ }
TileIndex::Animated(start, end, speed) => { /* Do something */ }
}
}
瓦片类型
目前有四种主要的瓦片类型
🖼 标准型
定义一个基本瓦片。
// assets/tiles/my-tile.ron
(
name: "My Tile",
tile: Standard("textures/my_tile.png")
)
🎞️ 动画型
定义一个可以由 bevy_ecs_tilemap
中的 GPUAnimated
组件生成的动画瓦片。
// assets/tiles/my-animated-tile.ron
(
name: "My Animated Tile",
tile: Animated((
speed: 2.25,
frames: [
"textures/animated-001.png",
"textures/animated-002.png",
"textures/animated-003.png",
]
))
)
🎲 变体型
启用
variants
功能
定义一个具有一组可能变体的瓦片。放置时随机选择一个变体。这些变体可以是标准型或动画型。
// assets/tiles/my-variant-tile.ron
(
name: "My Crazy Random Tile",
tile: Variant([
(
weight: 1.0,
tile: Standard("textures/variant-standard-001.png")
),
(
// Default weight: 1.0
tile: Standard("textures/variant-standard-002.png")
),
(
weight: 0.0001, // Wow that's rare!
tile: Animated((
// Default speed: 1.0
frames: [
"textures/variant-animated-001.png",
"textures/variant-animated-002.png",
"textures/variant-animated-003.png",
]
))
)
])
)
🧠 自动型
启用
auto-tile
功能
定义一个根据其邻居自动选择活动瓦片的瓦片。此行为可以用规则控制。这些子瓦片本身是变体型瓦片。
// assets/tiles/my-auto-tile.ron
#![enable(implicit_some)]
(
name: "My Auto Tile",
tile: Auto([
(
rule: (
north: true,
east: false,
west: true,
),
variants: [
(
tile: Standard("textures/n_w-e-001.png")
),
(
weight: 2.0,
tile: Standard("textures/n_w-e-002.png")
)
]
),
(
rule: (
// Also supports short notation
n: false,
s: false,
// And ordinal directions
south_west: true,
nw: false
),
variants: [
(
tile: Standard("textures/sw-n_s_nw.png")
)
]
),
])
)
🎓 示例
请务必查看 assets 文件夹以了解如何定义瓦片或瓦片集。
🌱 发展领域
这个工具包在某些方面可以做得更好。以下是一些潜在的发展领域
- 瓦片集
- 配置文件 ★
- 改进的自动瓷砖
- 镜像/旋转(指定要镜像或旋转的规则)
- 加载
- 将配置作为资产加载
以及一个整体改进且更干净的API。
🎵 重要提示
这些瓷砖是用 bevy_ecs_tilemap
库定义的。因此,它旨在与基于索引的瓷砖系统(其中瓷砖的纹理被定义为纹理图集中的索引)一起工作。其他解决方案可能需要适应才能与这个库一起工作。
🕊 Bevy 兼容性
bevy | bevy_tileset |
---|---|
0.11 | 0.8 |
0.10 | 0.7 |
0.9 | 0.6 |
0.8 | 0.5 |
0.7 | 0.4 |
0.6 | 0.3 |
0.5 | 0.2 |
依赖项
~38–73MB
~1M SLoC