1.5 KiB
1.5 KiB
title, category, tags, mentions
| title | category | tags | mentions | ||||
|---|---|---|---|---|---|---|---|
| 禁用粒子效果 | 巧思案例 |
|
|
禁用粒子效果
当你需要禁用某个粒子效果时,建议直接在粒子文件中进行禁用,而不是简单地在 particles.png 中将粒子纹理设为透明。此外,与透明化处理相比,完全禁用粒子可能会带来小幅性能提升,因为透明粒子仍会被发射(只是不可见)。
禁用粒子发射的基本原理如下:
::: code-group
{
"format_version": "1.10.0",
"particle_effect": {
"description": {
"identifier": "minecraft:some_vanilla_particle",
"basic_render_parameters": {
"material": "particles_alpha",
"texture": "textures/particle/particles"
}
},
"components": {
"minecraft:emitter_lifetime_expression": {
"activation_expression": 0, // 立即激活
"expiration_expression": 1 // 立即结束生命周期(单位:秒)
},
"minecraft:emitter_rate_manual": {
"max_particles": 0 // 设置最大粒子生成数为0
}
}
}
}
:::
实现原理说明:
- 通过
emitter_lifetime_expression组件将粒子发射器的生命周期设为瞬时(0秒激活,1秒后过期) - 使用
emitter_rate_manual组件将最大粒子数设为0,彻底阻止粒子生成 - 保留原始渲染参数确保兼容性,但实际不会产生任何可见粒子