Sprites, Primitives and logic entity as structs
Posted
by
Jeffrey
on Game Development
See other posts from Game Development
or by Jeffrey
Published on 2012-12-09T17:57:56Z
Indexed on
2012/12/09
23:45 UTC
Read the original article
Hit count: 312
I'm wondering would it be considered acceptable:
The window class is responsible for drawing data, so it will have a method:
Window::draw(const Sprite&);
Window::draw(const Rect&);
Window::draw(const Triangle&);
Window::draw(const Circle&);
and all those primitives + sprites would be just public struct. For example Sprite:
struct Sprite {
float x, y; // center
float origin_x, origin_y;
float width, height;
float rotation;
float scaling;
GLuint texture;
Sprite(float w, float h);
Sprite(float w, float h, float a, float b);
void useTexture(std::string file);
void setOrigin(float a, float b);
void move(float a, float b); // relative move
void moveTo(float a, float b); // absolute move
void rotate(float a); // relative rotation
void rotateTo(float a); // absolute rotation
void rotationReset();
void scale(float a); // relative scaling
void scaleTo(float a); // absolute scaling
void scaleReset();
};
So instead of having each primitive to call their draw()
function, which is a little bit off topic for their object, I let the Window class handle all the OpenGL stuff and manipulate them as simple objects that will be drawn later on.
Is this pattern used? Does it have any cons against it's primitives-draw-themself
pattern? Are there any other related patterns?
© Game Development or respective owner