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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Falke88

Pages: [1] 2 3 ... 5
1
I got you there. I thought there would be a other way around. So i can assign the render states Transform to the sprite.

2
_sprite.Transform = _sprite.Transform.Combine(states.Transform);

The problem is I can't assign the returned Transform because its read-only. So I don't see a way to assign _sprite's Transform to the Transform within "states".

3
Hey my friends! It's me again!

The above problem was solved and I successfully could decouple the Sprite from my GameObject.

Now I have a new problem which lets me thing about if I should couple Sprite to the GameObject again.

We want to have a collision check. Since Sprite Draw Position is actually temporarily because of the way I used states (see above) and its Transform - The Sprite Position is never updated with the GameObjects Position. The Drawing works well but collision checks will be wasted.

I could do the following after Sprite is coupled to the GameObject:



_sprite.Position = _player.Position;
 

I don't like that because I'd have to couple stuff.

What I tried should work but it doesn't. I think I just use the method the wrong way.

My Approach:

Since I multiplied the GameObject's Transform (this) to the states - states now holds the Position for the GameObject:



The next call is the Draw Method within the Render-Class (which owns the Sprite object)



Why I've chosen the Combine-Method here? Because the Doc tells me it works like multiplie (which I used in the GameObject-Class above) and I can't "combine" it otherwise because the Sprite's Transform is immutable)



Sadly _sprite.Position did not changed as you can see in this debug (Breakpoint active @ 100 iterations of Draw-Method)




I hope I provided you guys with enough information about the problem!
I'd really like to keep things decoupled but still changing the _sprite.Position.


Thanks for any help in advance


Charlie

4


AH ! I managed it !

I never was thinking about "states" being some kind of transporter through the method so I can assign Transform Values to it while its going through my Draw-Method. Kinda cool way!


Thanks for you time anyway!

5
I'm sure it's well documentated. But I'm also sure I'm too dumb to find it :D


Here is my Draw-Method. It's within an Render Object. Because I wanted a little decoupling from the Actor-Class.



It is called from here the Actor's Draw-Method FYI:



Can you mybe give a hint on how to approach now? I read through the doc, the Transformable Class and the Transform Class. But I find a lot of ways which may fit - but still I don't even know how I should use them.
Should I use Translate() or just multiply.
You see I'm a bit overwhemled by the possibilites :D


Thanks in advance!


6
Hey Guys!

I have a little thing I would like to make more nicer.

I have a Class called "Actor" - it contains a Sprite Object.

Both are inheriting from "Transformable" - so both have a unqiue Position Vector.
Is there a way to merge the Sprite's Position to the Actor's one?
I could assign "sprite.Position = actor.Position;" for sure.
But maybe theres a nicer solution to do this. Something with Transform mybe.
Sadly I'm not that fresh with that.


greets Charluie

7
I believe I figured out what's happening here. You are setting your sprites' position twice. You already set the position of your sprites on update. Then on Draw, you apply entity's current transform (position) into renderstates.  SFML.Graphics.Sprite is a Transformable too so you are actually drawing sprite into entity's position + sprite's position. Result is that the sprites position property doesn't represent what you see on screen, it's real position is actually to the left but it's drawn more to the right.

If you comment states states.Transform *= this.Transform; it works. But I'd suggest you to implement your own GetGlobalBounds for entities/physicsobjects instead. Chances are you're gonna need a different bounding box from the sprite anyway (ie. sprite is not cropped or has empty space around it) so I think it'd be a good idea to do that first. Separating things like this from sprites and drawing is a good idea anyway imo.


Thanks for the tip - it really was that issue. I just need to figure out what to change now exactly - because having an Transformable Object without having it transform being changed when commenting out the mentioned code is a bit redundant.

I think I'm gonna apply a BoundingBox in my Player Class which depends on position and known dimensions of the texture of the sprite. That way it doesn't matter whats up with the drawn position etc.

8
A little hint to find the solution by myself would be already enough brothers!

9
DotNet / Re: Sprite within Object won't move with it
« on: February 22, 2015, 06:45:47 pm »
Quote
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.
Is that a different problem?


Ah yeh sorry, I was to thrilled to realize that I already gave up a new question - changed it myself already

10
DotNet / Object.Position and Object.sprite's displayed texture don't match
« on: February 22, 2015, 06:45:05 pm »
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!");
                }
            }
        }
    }
}

 

11
DotNet / Re: Sprite within Object won't move with it
« on: February 22, 2015, 03:57:30 pm »
Odd if I wanted to make a sprite within a sprite I'd just set the sprite that should be in the same place as the other to its position directly.  Or if a follow sprite make its vector aim toward it.


Basically it would be like this for sprite within sprite> Sprite A Pos = Sprite B Pos


As for what's wrong with transform I got no clue.  Maybe the original position of the sprite isn't changing.


Hey there,

Well be sure that I already made that "odd" way. But in my already advanced code I came over some ugly glitches with this way - thats why I wanted to try it out with this transform.

Well the sprite position isn't changing thats right but also the position of Player isn't - when I debuglog this.Transform the values are always the same - take a look above at my first post - same reaction

12
DotNet / Re: Sprite within Object won't move with it
« on: February 22, 2015, 01:26:44 pm »
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();
            }
        }
    }
}
 

13
DotNet / Re: Sprite within Object won't move with it
« on: February 22, 2015, 09:42:43 am »
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!

14
DotNet / Re: Sprite within Object won't move with it
« on: February 22, 2015, 07:53:05 am »
And what would make the sprite magically follow its owner entity? The usual solution to this problem is to apply the Player's transform to the RenderStates in the DrawCurrent function. See the C++ tutorials for more details.

Ha don't get me wrong - I surely know that it wouldn't magically follow. But I wrote the whole stuff side by side with the book. Many things I understood - but I surely missed out the part where I should have realized how the sprite is being moved within the Players boundaries dynamically.


Will check out the transform stuff and hopefully don't have to come back here :)

15
DotNet / Sprite within Object won't move with it
« on: February 21, 2015, 11:25:32 pm »
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;
        }
    }
}
 

Pages: [1] 2 3 ... 5