Skip to content

Low level

Alexandre edited this page Sep 13, 2018 · 6 revisions

"Low level stuff"

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

Drawable is the trait that help implement all that can be draw on a target.

Example

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

Drawer is the trait where something can be render. For now there is only window, maybe there will be texture. or others.

Movable

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.

Important

Thoses examples are bad. If you want to make a game use Rame.

Clone this wiki locally