SFML community forums
Bindings - other languages => DotNet => Topic started by: cjlucas on April 04, 2011, 09:16:40 am
-
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:
S.Position.X = 10;
S.Position.Y = 10;
But you can do this...
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.
-
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.
-
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:
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.
-
???
They are not missing. They've been transformed into properties, as you noticed in your first post.
-
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.
-
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.