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

Pages: [1]
1
Graphics / Re: Entire screen is flipped on Y axis!
« on: June 09, 2017, 07:12:52 pm »
thanks :)

2
Graphics / Entire screen is flipped on Y axis!
« on: June 09, 2017, 04:45:53 pm »
I'm totally mystified!
I'm using SFML.Net, and my entire window seems to have got flipped somehow on the Y axis?

The only thing I could see that could be causing it is RenderTextures - I'm rendering my entire game to a RenderTexture, then updating a Sprite's texture with it, scaling by 2 with smoothing off and then rendering the sprite - for pixelly scaling in a retro styled game

Somewhere along the way it's flipped the Y axis though! Am I doing this right (could this be done better with Views?) - and do you have any idea what the issue is?
I've put my two classes dealing with rendering in code blocks below.

Code:

Game.cs:
class Game
    {
        RenderWindow window;
        List<Entity> entities;
        Tilemap tilemap;
        VertexArray verts;
        RenderTexture buffer;
        Sprite bufferSprite;
        CircleShape circle;

        private int[] tiles = new int[]
        {
            13, 3, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
            1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0
        };

        public Game(RenderWindow window)
        {
            this.window = window;
            tilemap = new Tilemap();
            tilemap.LoadContent("res\\img\\tiles_packed.png", tiles);
            entities = new List<Entity>();
            verts = new VertexArray(PrimitiveType.Quads, 4);

            buffer = new RenderTexture(window.Size.X / 2, window.Size.Y / 2);
            buffer.Smooth = false;

            circle = new CircleShape(50);
            circle.FillColor = Color.Green;
            circle.Position = new Vector2f(200, 50);

            bufferSprite = new Sprite(buffer.Texture);

            //buffer.
        }

        public void Update(float dt)
        {
            //entities.Where(x => x is IUpdateable).
            for (int i = 0; i < entities.Count; i++)
            {
                entities[i].Update(dt);
            }
        }

        public void Draw()
        {            
            window.Clear(Color.White);
            buffer.Clear(Color.White);
            for (int i = 0; i < entities.Count; i++)
            {
                entities[i].Draw(buffer);
            }
            buffer.Draw(tilemap);

            buffer.Draw(circle);



            // scale buffer 2x
            //bufferSprite = new Sprite(buffer.Texture);
            bufferSprite.Texture = buffer.Texture;
            bufferSprite.Scale = new Vector2f(2, 2);
           
           
            //RenderStates states = new RenderStates()
            window.Draw(bufferSprite);
            //window.Draw(verts);
        }
    }
 

Program.cs (contains entry point)
class Program
    {
        static void Main(string[] args)
        {
            RenderWindow window;
            window = new RenderWindow(new VideoMode(800, 600), "Mine cart madness");

            window.Closed += Window_Closed;

            float dt = 1.0f / 60.0f;
            float accumulator = 0;
            Clock clock = new Clock();

            Game game = new Game(window);
           

            while (window.IsOpen)
            {
                Time elapsed = clock.Restart();
                float elapsedTime = elapsed.AsSeconds();
                accumulator += elapsedTime;
                while (accumulator > dt)
                {
                    accumulator -= dt;
                    window.DispatchEvents();
                    game.Update(dt);
                }

                game.Draw();
                window.Display();
            }
        }

        private static void Window_Closed(object sender, EventArgs e)
        {
            ((RenderWindow)sender).Close();
        }
    }
 

Any ideas?

EDIT: output:


That circle is centred at 200, 50!


Pages: [1]
anything