-
Notifications
You must be signed in to change notification settings - Fork 0
Low level
Alexandre edited this page Sep 13, 2018
·
6 revisions
Low level stuff (if we use these terms) are made for you if you really want to add you own struct and implement you own gust compatibles structs !
Drawable is the trait that help implement all that can be draw on a target.
Right now you can add for example a player.
struct Player {
sprite: Sprite,
name: String,
life_point: i32,
inventory: Inventory, // Created by your incredible brain
}
impl Drawable for Player {
fn draw<T: Drawer>(&self, drawer: &mut T) {
self.sprite.draw();
}
...
}
That way you can draw directly the player in the target.
let player = Player::new();
window.draw(&player);
Drawer is the trait where something can be render. For now there is only window, maybe there will be texture. or others.
Movable is the trait that permit to something to move in a transformation way. (Scale, translate etc...)
Let's say that you want your player to move ! (Incredible ...)
impl Movable for Player {
fn translate<T: Scalar ...>(&mut self, offset: Vector<T>) {
self.sprite.translate(offset);
}
...
}
Now your player can move.
Thoses examples are bad. If you want to make a game use Rame.
Gust wiki A.F.