英文:
ggez Rectangle doesn't show up on canvas
问题
我正在尝试在白色画布上用ggez绘制一些黑色矩形。我已经看过ggez文档中链接到的生成艺术示例。
我的问题是,矩形没有显示出来,我只得到了一个白色画布。我已经调试过了,以确保它正确进入绘制分支,它确实进入了,所以我猜这可能与我如何使用ggez有关。
fn draw(&mut self, ctx: &mut ggez::Context) -> GameResult {
let mut canvas = graphics::Canvas::from_frame(ctx, Color::WHITE);
for i in 0..GRID_SIZE.0 {
for j in 0..GRID_SIZE.1 {
if self.grid[i][j] {
let rect = Mesh::new_rectangle(
ctx,
DrawMode::fill(),
Rect::new(
i as f32 * CELL_SIZE.0,
j as f32 * CELL_SIZE.1,
CELL_SIZE.0,
CELL_SIZE.1,
),
Color::BLACK,
)?;
canvas.draw(&rect, DrawParam::default());
}
}
}
canvas.finish(ctx)?;
Ok(())
}
英文:
I am trying to draw some black rectangles on a white canvas with ggez. I've looked at the Generative Art example that's linked at in the ggez docs.
My problem is, I'm not getting the rectangles to show up, all I get is a white canvas. I've debugged this to see if it correctly enters the draw branch and it does, so I guess there must be an issue with how I use ggez.
fn draw(&mut self, ctx: &mut ggez::Context) -> GameResult {
let mut canvas = graphics::Canvas::from_frame(ctx, Color::WHITE);
for i in 0..GRID_SIZE.0 {
for j in 0..GRID_SIZE.1 {
if self.grid[i][j] {
let rect = Mesh::new_rectangle(
ctx,
DrawMode::fill(),
Rect::new(
i as f32 * CELL_SIZE.0,
j as f32 * CELL_SIZE.1,
CELL_SIZE.0,
CELL_SIZE.1,
),
Color::BLACK,
)?;
canvas.draw(&rect, DrawParam::default());
}
}
}
canvas.finish(ctx)?;
Ok(())
}
答案1
得分: 0
显然,在使用新的Rust编译器(在我这里是1.70.0)时,使用ggez v0.8.1存在问题。使用ggez的v0.9.0-rc0版本已经解决了矩形不显示的问题。
ggez仓库上的相应问题可以在这里找到。
英文:
Apparently there is a problem when using ggez v0.8.1 with newer rust compilers (1.70.0 in my case). Using v0.9.0-rc0 of ggez has fixed my problem with rectangles not showing up.
The corresponding issue on the ggez repo can be found here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论