Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Origins and positions  (Read 1674 times)

0 Members and 1 Guest are viewing this topic.

solver

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Origins and positions
« on: May 15, 2013, 03:01:30 pm »
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);
}

gostron

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Origins and positions
« Reply #1 on: May 15, 2013, 04:17:18 pm »
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.

solver

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Origins and positions
« Reply #2 on: May 15, 2013, 07:06:10 pm »
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

gostron

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Origins and positions
« Reply #3 on: May 16, 2013, 03:03:11 pm »
May I enquire why you would reimplement the SFML ?

If you want to do so, you can look at SFML code directly