(D)SFML update position of shape automatically

135 views Asked by At

I created a simple little programm in D with the D-bindings to SFML. And I'm currently reading about the custom transformations and custom shapes.

Now I created a class

class Animal : Drawable, Transformable
{
    mixin NormalTransformable;

    Shape body;
    string name;

    this(Shape sh, string name) {
        this.body = sh;
        this.name = name;
    }

    override void draw(RenderTarget target, RenderStates state = RenderStates.Default) {
        body.position = this.position;
        target.draw(body);
    }
}

This is D code, but I think most of the stuff except the mixin should be quite the same in C++.

Now my question is mainly about this line body.position = this.position; in the draw method.

Is it necessary to update the position of the shape manually? This seems a bit wrong but I do not find any ressource that shows me how to automate this process. Also doing this in draw feels a bit like a deadly sin to me.

So basically my question is:

How do I draw my own drawables according to the stuff that happens to it by the methods from the transformable interface.

Or even simpler:

How do I synchronize the position, scale, rotation, ... from the object and the shape automatically?

0

There are 0 answers