Heya guys!
Long time no posting - which actually seems to be good because I know that I can solve many problems on my own with SFML.NET :P
Still I'm back to some fundamental problem here.
I have a class called "Player" which contains a Sprite object.
While changing "Player"'s Position my Sprite wont move. Player.Position has been moved. Sprite.Position hasn't.
Actually I thought that the sprite within a class would move with it aswell?
I worked with the SFML.NET Dev Book Tutorials.
Here is the Code:
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 Player
: Entity
{ int health
; float speed
; string id
; Sprite sprite
; ResourceHolder
<Texture, TextureID
> textures
; public Player
(ResourceHolder
<Texture, TextureID
> textures
) { this.health = 100; this.speed = 100; this.textures = textures
; sprite
= new Sprite
(textures
.Get(TextureID
.MackMoving)); } //[... Property Getter & Setter] public override void DrawCurrent
(RenderTarget target, RenderStates states
) { target
.Draw(sprite
); } public override void UpdateCurrent
(Time dt
) { Position
+= base.velocity; } public override uint GetCategory
() { return (uint)Category
.Player; } }}
Well I tried things and they didn't work out.
I reviewed my old SFML Game Development Book Tutorial Project.
There I found this piece within the "AircraftMover.cs"
public override void UpdateCurrent(Time dt)
{
this.Transform.Translate(velocity * dt.AsSeconds());
}
I'm using this but the Translate() method isn't working properly.
I implemented it as followed:
public override void UpdateCurrent(Time dt)
{
this.Transform.Translate(50.0f, 0.0f);
}
Debug log:
Player
.Position = new Vector2f
(20
.0f, 330
.0f
)
this.Transform = {[Transform] Matrix(1, 0, 20,0, 1, 330,0, 0, 1, )}
this.Transform = {[Transform] Matrix(1, 0, 20,0, 1, 330,0, 0, 1, )}
this.Transform = {[Transform] Matrix(1, 0, 20,0, 1, 330,0, 0, 1, )}
this.Transform = {[Transform] Matrix(1, 0, 20,0, 1, 330,0, 0, 1, )}
this.Transform = {[Transform] Matrix(1, 0, 20,0, 1, 330,0, 0, 1, )}
as you can see no change had happened there :/ why is that? If I could fix this I think I have a solution!
Alright I managed to reproduce the problem as tiny as possible :D
You can see that I use Transform.Translate - but it doesn't affect anything as I mentioned before.
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
= 1
.0f
; public override void UpdateCurrent
(float deltaTime
) { this.Transform.Translate(velocity, 0
.0f
); // is NOT working //this.Position += velocity * new Vector2f(deltaTime, 0.0f); // is working } } class TestPlayer
: EntityTest
{ public Sprite sprite
; public TestPlayer
() { sprite
= new Sprite
(new Texture
("./Resources/Test/TestTxt.png")); } public override void DrawCurrent
(RenderTarget target, RenderStates states
) { target
.Draw(sprite, states
); } } class TestClass
{ RenderWindow window
; TestPlayer player
; public TestClass
() { window
= new RenderWindow
(new VideoMode
(640,
480),
"TestClass"); player
= new TestPlayer
(); player
.Position = new Vector2f
(100
.0f, 100
.0f
); } public void Run
() { while(window
.IsOpen) { window
.DispatchEvents(); player
.UpdateCurrent(0
.016f
); window
.Clear(Color
.Blue); window
.Draw(player
); window
.Display(); } } }}