SFML community forums

Bindings - other languages => DotNet => Topic started by: Enok on November 20, 2014, 02:41:13 pm

Title: Set sprite origin.
Post by: Enok on November 20, 2014, 02:41:13 pm
Hello.

Setting the sprite origin doesn't seem to work.

I can't really see what I'm doing wrong here, everything else works just fine. I can't set the Origin even if I do it directly to the sprite itself, rather than using properties.

        public void LoadContent()
        {
            player.Origin = new Vector2f(player.Scale.Y, player.Scale.Y) / 2;
        }
 

        public Vector2f Origin { get { return this.sprite.Origin;  } set { this.sprite.Origin = value;  } }
 
Title: Re: Set sprite origin.
Post by: eXpl0it3r on November 20, 2014, 02:54:16 pm
And how do you verify that "it doesn't work"?
Title: Re: Set sprite origin.
Post by: Enok on November 20, 2014, 02:57:28 pm
It doesn't do anything. It doesn't change the origin, nothing happens. There's no difference with or without it. No matter what numbers I type in, the sprites origin is always in the top-left.
Title: Re: Set sprite origin.
Post by: eXpl0it3r on November 20, 2014, 03:01:33 pm
Provide a complete and minimal example.
Title: Re: Set sprite origin.
Post by: Enok on November 20, 2014, 03:07:24 pm
This is what it looks like when I just draw the sprite.
(http://puu.sh/cYpfZ/a3278783be.jpg)

This is what it looks like with player.Origin = new Vector2f(50,50);
(http://puu.sh/cYpik/3149cb3b54.jpg)


Game.cs
namespace PointAndClick
{
    class Game
    {

        Player player = new Player();



        public void LoadContent()
        {
            player.Texture = new Texture(Converter.ToSFTexture(Resources.spr_cannon_barrel));
            player.Origin = new Vector2f(50, 50);
        }

        //Physics, move stuff.
        public void FixedUpdate(TimeSpan deltaTime)
        {

        }

        //Draw stuff, check for input
        public void Update(RenderWindow rWindow)
        {
            rWindow.Clear(new Color(25,18,63));
            player.Draw(rWindow);
            rWindow.Display();
        }

        public static void UnloadContent()
        {

        }
    }
}
 
Player.cs
namespace PointAndClick
{
    public class Player
    {
        private Sprite sprite = new Sprite();

        //Transform
        public Vector2f Position { get { return this.sprite.Position; } set { this.sprite.Position = value; } }
        public Vector2f Scale    { get { return this.sprite.Scale;    } set { this.sprite.Scale = value;    } }
        public float Rotation    { get { return this.sprite.Rotation; } set { this.sprite.Rotation = value; } }

        public Texture Texture { get { return this.sprite.Texture; } set { this.sprite.Texture = value; } }
        public Vector2f Origin { get { return this.sprite.Origin;  } set { this.sprite.Origin = value;  } }
       
        public void Draw(RenderWindow rWindow)
        {
            rWindow.Draw(this.sprite);
        }
    }
}
 

Title: Re: Set sprite origin.
Post by: Ztormi on November 20, 2014, 04:24:44 pm
^^ Works fine.

(click to show/hide)
Title: Re: Set sprite origin.
Post by: Enok on November 20, 2014, 05:25:45 pm
The hell.. I'm gonna compile the latest source and try again..