Please take a look at the code - run it once.
the intersecting of player1 and player2 is mathmatically right - but the displayed sprite of player2 kinda doesn't look right, because player1 isn't hitting it really. I already checked the bounds and positions of player2 and its sprite - can't find a solution.
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using SFML.Graphics;using SFML.Window;using SFML.System;namespace KompanieGame
{ class SceneNodeTest
: Transformable, Drawable
{ public virtual void UpdateCurrent
(float deltaTime
) { } public void Draw
(RenderTarget target, RenderStates states
) { states
.Transform *= this.Transform; DrawCurrent
(target, states
); } public virtual void DrawCurrent
(RenderTarget target, RenderStates states
) { } } class EntityTest
: SceneNodeTest
{ float velocity
= 5
.0f
; public override void UpdateCurrent
(float deltaTime
) { this.Position += velocity
* new Vector2f
(deltaTime, 0
.0f
); } } class TestPlayer
: EntityTest
{ public Sprite sprite
; public TestPlayer
() { sprite
= new Sprite
(new Texture
("./Resources/Test/TestTxt.png")); } public override void UpdateCurrent
(float deltaTime
) { base.UpdateCurrent(deltaTime
); sprite
.Position = this.Position; } public override void DrawCurrent
(RenderTarget target, RenderStates states
) { target
.Draw(sprite, states
); } } class TestClass
{ RenderWindow window
; TestPlayer player1
; TestPlayer player2
; public TestClass
() { window
= new RenderWindow
(new VideoMode
(640,
480),
"TestClass"); player1
= new TestPlayer
(); player2
= new TestPlayer
(); player1
.Position = new Vector2f
(0
.0f, 0
.0f
); player2
.Position = new Vector2f
(50
.0f, 0
.0f
); player2
.sprite.Position = player2
.Position; } public void Run
() { while(window
.IsOpen) { window
.DispatchEvents(); player1
.UpdateCurrent(0
.016f
); window
.Clear(Color
.Blue); window
.Draw(player1
); window
.Draw(player2
); window
.Display(); if (player1
.sprite.GetGlobalBounds().Intersects(player2
.sprite.GetGlobalBounds())) { Console
.WriteLine("Hit!"); } } } }}