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

Author Topic: Set* methods don't display for Sprite  (Read 3254 times)

0 Members and 1 Guest are viewing this topic.

cjlucas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Set* methods don't display for Sprite
« on: April 04, 2011, 09:16:40 am »
Code: [Select]

Sprite S = new Sprite("Image.Jpg");
S.SetPosition(10, 10);


In the tutorial this should work for the C++ version of SFML; however, this gives an error indicating that SetPosition doesn't exist. When I use intellisense, none of the Set* methods exist (or at least they're not public). This is a bit perplexing as it seems like you can alternatively move based on setting the S.Position; however, you cannot do the following:

Code: [Select]

S.Position.X = 10;
S.Position.Y = 10;


But you can do this...

Code: [Select]

S.Position = new Vector2(10f, 10f);


I'd really hate to think I'd have to create a new object every time I want to set the position, so I'd like someone to tell me whether I'm doing this wrong of fix this problem. Thanks in advance.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Set* methods don't display for Sprite
« Reply #1 on: April 04, 2011, 10:01:14 am »
Well, this is the same as in C++: you can't call "sprite.GetPosition().x = 5", you must set the position all at once. Properties in .Net work like a getter/setter pair, there's no "Position" variable in Sprite that would allow accessing its x/y members directly.

The "new" keyword in C# is not as heavy as in C++, basically everything's allocated with it so it's ok.
Laurent Gomila - SFML developer

cjlucas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Set* methods don't display for Sprite
« Reply #2 on: April 04, 2011, 10:26:53 am »
Right, the post has more to do with the fact that the Set* methods are missing in the DotNet wrapper for the SFML. Here is some code you can put into Sprite.cs in order to get these exposed to DotNet:

Code: [Select]

            public void SetColor(byte red, byte green, byte blue, byte alpha)
            {
                sfSprite_SetColor(This, new Color(red, green, blue, alpha));
            }
            public void SetPosition(float x, float y)
            {
                sfSprite_SetPosition(This, x, y);
            }
            public void SetX(float x)
            {
                sfSprite_SetX(This, x);
            }
            public void SetY(float y)
            {
                sfSprite_SetY(This, y);
            }
            public void SetRotation(float Rotation)
            {
                sfSprite_SetRotation(This, Rotation);
            }
            public void SetCenter(float x, float y)
            {
                sfSprite_SetCenter(This, x, y);
            }
            public void SetScale(float x, float y)
            {
                sfSprite_SetScale(This, x, y);
            }
            public void SetScaleX(float x)
            {
                sfSprite_SetScaleX(This, x);
            }
            public void SetScaleY(float y)
            {
                sfSprite_SetScaleY(This, y);
            }
            public void SetBlendMode(BlendMode Mode)
            {
                sfSprite_SetBlendMode(This, Mode);
            }

            // Additional Imports
            [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
            static extern void sfSprite_SetScaleX(IntPtr This, float x);

            [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
            static extern void sfSprite_SetScaleY(IntPtr This, float y);

            [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
            static extern void sfSprite_SetX(IntPtr This, float x);

            [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
            static extern void sfSprite_SetY(IntPtr This, float y);


Every method was tested to see if it works. The only ones that I am not 100% sure of is the SetCenter and SetBlendMode because I don't have a clue what they're trying to do.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Set* methods don't display for Sprite
« Reply #3 on: April 04, 2011, 10:47:55 am »
???

They are not missing. They've been transformed into properties, as you noticed in your first post.
Laurent Gomila - SFML developer

cjlucas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Set* methods don't display for Sprite
« Reply #4 on: April 04, 2011, 11:47:20 am »
Alright, I see what you're saying now. This should probably be mentioned in the tutorials; there's almost nothing in there about the DotNet library, so I went off the assumption that it was going to be supplied with the same member interface.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Set* methods don't display for Sprite
« Reply #5 on: April 04, 2011, 12:11:20 pm »
It's the same interface, but transformed in the .Net way.

There are not tutorials, only the auto-generated API documentation. Looking at it you should easily notice that each Set/Get are transformed to a property.
Laurent Gomila - SFML developer