Hands-on Rust: dungeon_crawl_player: Order of map/player render steps (Page 88)

After playing with the code and testing the results of swapping the order it became clear why this order was used:

impl GameState for State {
    fn tick(&mut self, ctx: &mut BTerm) {
        ctx.cls();
        self.player.update(ctx, &self.map);
        self.map.render(ctx);
        self.player.render(ctx);
    }
}

instead of this order, which renders the player before the map:

impl GameState for State {
    fn tick(&mut self, ctx: &mut BTerm) {
        ctx.cls();
        self.player.update(ctx, &self.map);
        self.player.render(ctx);
        self.map.render(ctx);
    }
}

Suggestion: Perhaps add a short note to indicate that the order of the steps is important (though it may be implied).

1 Like

Thank you! I’ve added this to the issue tracker. It may make beta 3, or may be in beta 4 - we’re starting to wrap up for the next release (and I’ll be offline over the weekend taking care of family matters). It looks simple enough to get a note in - just not sure about timing.

2 Likes