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 - JohnyBro

Pages: [1]
1
General / Re: Player position
« on: May 10, 2017, 05:54:25 am »
Ok I found why it wasn't working correctly.

I use a vertexArray for drawing my player and the position of each verticies is the position of the player and in the Draw() method I did this

states.Transform *= Transform;

So the position of each verticies (the player's position) was calculated twice.

2
General / Re: Player position
« on: May 09, 2017, 10:48:15 pm »

3
General / Re: Player position
« on: May 09, 2017, 06:06:36 pm »
No im using the default view.

Here is my github if you need the code https://github.com/JohnyBro/Danmaku

4
General / Player position
« on: May 09, 2017, 11:44:59 am »
Hi

This is my RenderWindow
window = new RenderWindow(new VideoMode(1920, 1080), "SFML");

And when I set the position of my player at 1920/2 x 1080/2 he is at the bottom right of the window and not in the center, why ?

Here is my player code

class Player : Transformable, Updatable, Drawable, HasFloatRect
    {
        Vector2f size;
        Texture texture;
        float speed = 300;
        VertexArray vertexArray;

        public Player()
        {
            texture = RessourceManager.Instance.createTexture("player.png");
            size = new Vector2f(texture.Size.X, texture.Size.Y);
            Origin = new Vector2f(size.X / 2, size.Y / 2);
            vertexArray = new VertexArray(PrimitiveType.Quads, 4);
            Position = new Vector2f(960f, 540f);
        }

        public void Draw(RenderTarget target, RenderStates states)
        {
            states.Transform *= Transform;
            states.Texture = texture;
            target.Draw(vertexArray, states);
        }

        public void Update(Time elapsedTime)
        {
            checkInput(elapsedTime);
            updateVertexArray();
        }

        private void updateVertexArray()
        {
            vertexArray[0] = new Vertex(Position, new Vector2f(0, 0));
            vertexArray[1] = new Vertex(Position + new Vector2f(size.X, 0), new Vector2f(texture.Size.X, 0));
            vertexArray[2] = new Vertex(Position + new Vector2f(size.X, size.Y), new Vector2f(texture.Size.X, texture.Size.Y));
            vertexArray[3] = new Vertex(Position + new Vector2f(0, size.Y), new Vector2f(0, texture.Size.Y));
        }

        private void checkInput(Time elapsedTime)
        {
            Vector2f direction = new Vector2f(0, 0);

            if (Keyboard.IsKeyPressed(Keyboard.Key.W))
            {
                direction += new Vector2f(0, -1);
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.A))
            {
                direction += new Vector2f(-1, 0);
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.S))
            {
                direction += new Vector2f(0, 1);
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                direction += new Vector2f(1, 0);
            }

            MyMath.normalize(ref direction);
            Position += direction * speed * elapsedTime.AsSeconds();
        }

        public FloatRect getAABB()
        {
            return new FloatRect(Position, new Vector2f(size.X, size.Y));
        }
    }

Pages: [1]