SFML community forums

Help => Graphics => Topic started by: Hugo on July 08, 2010, 11:41:02 pm

Title: Sprite's X and Y
Post by: Hugo on July 08, 2010, 11:41:02 pm
Can some one explain the getPosition function for the sprite's?

And

Can there be a way to get the sprite's x and y individually instead of both at the same time?

I need this for a directionToPosition function I want to make. For this I need arc tangents, mouseX mouseY, and player.x player.y

I may also need it for a nearestInstance Function

I will reward you with free to use for anything top down gun images, but they're just outlines so you have to color them...
Title: Sprite's X and Y
Post by: Mindiell on July 09, 2010, 09:07:30 am
getPosition is returning a Vector object which is simply a two value structure. Thoses values can be used as a vector, a position, etc...

To get the Sprite X and Y, it's very simple :
Code: [Select]
xValue = mySprite.GetPosition().x;
yValue = mySprite.GetPosition().y;



BTW, No need of a reward... Thanks
Title: Sprite's X and Y
Post by: Xorlium on July 09, 2010, 09:14:56 am
... and don't forget that GetPosition() returns the 'center' of the sprite (as defined by 'SetCenter').

At first (if you don't set it), that is the upper left corner, but you can set it to whatever you want. I recommend setting it to the center of the image. That is, setting it to (0.5*w,0.5*h), if w and h are the width and height of the image.
Title: Sprite's X and Y
Post by: Mindiell on July 09, 2010, 12:50:14 pm
Personaly, I would not recommend this. The upper-left corner can be as interesting as the real center. I think this is just a point of view.
By the way, your remind was a good one (about returning the center of the sprite)

Thx
Title: Sprite's X and Y
Post by: Hugo on July 09, 2010, 05:31:12 pm
Thanks guys!
this is what i got for a direction to x y, it works perfectly!
float directionTo(int x1, int y1, int x2, int y2)
{
    //take in variables
    float calc1 = x1 - x2;
    float calc2 = y1 - y2;
    //returns direction in radians, so we have to convert it to degrees, and then offset by -90 degrees
    return ((atan2(-calc1, -calc2))/3.14159265 * 180)-90;
}

And here's the promised top down sprite sheet:

http://tinypic.com/r/25a7ujt/3

Also, i know almost everything about sprites and object oriented programming, i got a headstart by using gamemaker for about a year, then i quit and started to learn c++
I'm doing a remake of my old game maker game
its a fun top down shooter with pretty graphics and your choice of enemies and weapons
Title: Sprite's X and Y
Post by: e_barroga on July 10, 2010, 09:56:15 am
Quote from: "Mindiell"
Personaly, I would not recommend this. The upper-left corner can be as interesting as the real center. I think this is just a point of view.


I disagree. But yeah, it is just a matter of point of view.
Title: Sprite's X and Y
Post by: Hugo on July 11, 2010, 12:19:43 am
i think the center is good if the sprite is going to be rotating a lot, otherwise stick with the upper left corner