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

Author Topic: Set sprite origin.  (Read 7100 times)

0 Members and 1 Guest are viewing this topic.

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
Set sprite origin.
« 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;  } }
 
« Last Edit: November 20, 2014, 03:54:03 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Set sprite origin.
« Reply #1 on: November 20, 2014, 02:54:16 pm »
And how do you verify that "it doesn't work"?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Set sprite origin.
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Set sprite origin.
« Reply #3 on: November 20, 2014, 03:01:33 pm »
Provide a complete and minimal example.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Set sprite origin.
« Reply #4 on: November 20, 2014, 03:07:24 pm »
This is what it looks like when I just draw the sprite.


This is what it looks like with player.Origin = new Vector2f(50,50);



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);
        }
    }
}
 

« Last Edit: November 20, 2014, 03:54:27 pm by eXpl0it3r »

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: Set sprite origin.
« Reply #5 on: November 20, 2014, 04:24:44 pm »
^^ Works fine.

(click to show/hide)
« Last Edit: November 20, 2014, 04:28:25 pm by Ztormi »

Enok

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Set sprite origin.
« Reply #6 on: November 20, 2014, 05:25:45 pm »
The hell.. I'm gonna compile the latest source and try again..

 

anything