Hi. I want to implement SFML-like functionality in my small project, because i cant use SFML/GL directly. So, I have a problem with understanding how 'origins' works. As you know setOrigin() doesn't changes position-property of the object, but changes on-screen position. I had to add realPos field to my base class. And when I calls my setOrigin() realPos changes. Here some examples:
public void setPosition(Vector2i position) {
this.position = position;
realPos = Vector2i.add(position, origin);
}
And one of draw methods:
@Override
public void draw
(Graphics target
) { target.
drawString(as.
getIterator(), realPos.
x, realPos.
y);}
As far as SFML is concerned, the origin gives the origin of the texture in the sprite.
For example, let's assume we have a square :
doing
square.setOrigin(width/2, height/2);
will mean that our texture won't be displayed from position, but from position-origin, meaning that our square image will have it's center at the "position" indicated, and no longer its left-top corner.
The origin is also the rotation center.
Yes, I know it. But I need technical details. For example, how I can implement drawning of any object:
target.drawSome(getOrigin() + getPosition(), params...);
Or
screenPos = getOrigin() + getPosition(); //In superclass
...
target.drawSome(realPos, params...); // In derivative class. getRealPos is protected field ob superclass