I am newer to using C# with SFML. I am having a problem with sprite transformations with views. In the game, when a mouse pressed event is triggered, the sprite is supposed to move to the position of the mouse click at a constant velocity over time. However, it does not always move to the correct position, which I believe is due to local versus global positions. Any idea on how to fix this issue?
My creation of the RenderWindow:
myProgram
.app = new RenderWindow
(new VideoMode
(5000,
5000),
"Game", Styles
.Fullscreen);My creation of the View:
VideoMode mode
= VideoMode
.DesktopMode;View view
= new View
(new Vector2f
(mode
.Width/2, mode
.Height/2),
new Vector2f
(mode
.Width, mode
.Height));Event method:
static void MouseButtonPressed
(object sender, MouseButtonEventArgs e
){ if (e
.Button == Mouse
.Button.Right) fighter
.MoveToPoint(new Vector2f
(Mouse
.GetPosition().X, Mouse
.GetPosition().Y));} Transformation Methods:
public void MovetoPoint(Vector2f inputCoord)
{
aTimer.Enabled = true;
inputPosition = inputCoord;
}
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
if (this.Length(inputPosition - this.Position) > 0)
this.Position = this.Position + (this.Normalize(inputPosition - this.Position) * (Math.Min(v, this.Length(inputPosition - this.Position))));
else
aTimer.Enabled = false;
}