amethyst / amethyst/bracket-lib

Multiple SpriteConsoles

未關閉
#152 3 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Rust
星號
1.7k
分支
126
PR 合併指標
30 天內沒有已合併 PR

描述

I tried your example at `bracket-lib/bracket-terminal/examples/sprites.rs` and changed it to use the same sprite a second time but with grayscale. Unfortunately trying to use the second SpriteConsole does not work as it will use the SpriteSheet of the first console and not the second. Now I'm wondering whether I'm doing something wrong:

Code:
```rs
bracket_terminal::add_wasm_support!();

use bracket_random::prelude::*;
use bracket_terminal::prelude::*;

struct Dood {
x: i32,
y: i32,
}

struct State {
frame: usize,
timer: f32,
doods: Vec,
rng: RandomNumberGenerator,
}

impl GameState for State {
fn tick(&mut self, ctx: &mut BTerm) {
ctx.set_active_console(1);
ctx.cls();
ctx.print(1, 1, "Watch them go!");
ctx.printer(
1,
2,
&format!("#[pink]FPS: #[]{}", ctx.fps),
TextAlign::Left,
None,
);

ctx.set_active_console(0);
ctx.cls();

for dood in self.doods.iter() {
ctx.add_sprite(
Rect::with_size(dood.x, dood.y, 32, 32),
400 - dood.y,
RGBA::from_f32(1.0, 1.0, 1.0, 1.0),
self.frame % 4,
)
}

self.timer += ctx.frame_time_ms;
if self.timer > 66.0 {
self.timer = 0.0;
self.frame += 1;

for dood in self.doods.iter_mut() {
dood.x += self.rng.range(0, 3) - 1;
dood.y += self.rng.range(0, 3) - 1;
}
}

// Changed
ctx.set_active_console(2);
ctx.cls();
ctx.add_sprite(
Rect::with_size(200, 200, 50, 50),
400,
RGBA::from_f32(1.0, 1.0, 1.0, 1.0),
0,
)
}
}

bracket_terminal::embedded_resource!(NYAN_CAT, "../res/sprite_dood.png");
// Changed
bracket_terminal::embedded_resource!(NYAN_CAT2, "../res/sprite_dood2.png");

fn main() -> BError {
bracket_terminal::link_resource!(NYAN_CAT, "res/sprite_dood.png");
// Changed
bracket_terminal::link_resource!(NYAN_CAT2, "res/sprite_dood2.png");

let context = BTermBuilder::new()
.with_sprite_console(640, 400, 0)
.with_font("terminal8x8.png", 8, 8)
.with_simple_console_no_bg(80, 50, "terminal8x8.png")
// Changed
.with_sprite_console(640, 400, 1)
.with_title("Bracket Terminal - Sprite Console")
.with_sprite_sheet(
SpriteSheet::new("res/sprite_dood.png")
.add_sprite(Rect::with_size(0, 0, 85, 132))
.add_sprite(Rect::with_size(85, 0, 85, 132))
.add_sprite(Rect::with_size(170, 0, 85, 132))
.add_sprite(Rect::with_size(255, 0, 85, 132)),
)
// Changed
.with_sprite_sheet(
SpriteSheet::new("res/sprite_dood2.png")
.add_sprite(Rect::with_size(0, 0, 85, 132))
.add_sprite(Rect::with_size(85, 0, 85, 132))
.add_sprite(Rect::with_size(170, 0, 85, 132))
.add_sprite(Rect::with_size(255, 0, 85, 132)),
)
.with_vsync(false)
.build()?;

let mut rng = RandomNumberGenerator::new();
let mut doods = Vec::new();
for _ in 0..100 {
doods.push(Dood {
x: rng.range(0, 640),
y: rng.range(0, 400),
});
}

let gs = State {
frame: 0,
timer: 0.0,
doods,
rng,
};

main_loop(context, gs)
}
```

This is my second sprite file:

![sprite_dood2](https://user-images.githubusercontent.com/15814071/87536299-303fb980-c699-11ea-960a-87f1d34b7c6b.png)

and this is the result:

![Screenshot from 2020-07-15 12-46-49](https://user-images.githubusercontent.com/15814071/87536385-4baac480-c699-11ea-966a-b105415eefc7.png)

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。