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

Pages: [1] 2
1
Graphics / Re: exception thrown issues
« on: July 05, 2020, 09:10:37 am »
To prevent bugs, I suggest using vectors and iterators instead of passing around raw arrays and making assumptions about their size.

2
Graphics / Re: Drawing line from vertices not visible when x = 0
« on: July 01, 2020, 05:06:47 am »
I found this: https://en.sfml-dev.org/forums/index.php?topic=20500.msg147365#msg147365

Adding 0.5 to my vertex coordinates seems to work, though it seems strange to me the different directions would behave differently.

Do I need to add 0.5 to other drawable objects? That post says "You should add 0.5 to all your coordinates", but when I draw a sf::RectangleShape at (0.5, 0.5), it is at the left edge but overcorrected down 1 pixel. (0, 0) works as expected. How can I know when I need this correction or not?

3
Graphics / Drawing line from vertices not visible when x = 0
« on: June 28, 2020, 03:47:33 am »
I am trying to draw a vertical line where x=0 but I can't see it. I have to use x=1 to see a line. However, for horizontal lines, I can see lines where y=0. I don't understand the difference in behavior.

sf::RenderWindow window(sf::VideoMode(640, 480), "fghjnufhg");

{

                        const std::array<sf::Vertex, 2> line =
                        {
                                sf::Vertex(sf::Vector2f(0, 0), sf::Color::Red),
                                sf::Vertex(sf::Vector2f(0, 100), sf::Color::Red)
                        };

                        window.draw(line.data(), line.size(), sf::Lines, sf::RenderStates::Default);
                }

                {

                        const std::array<sf::Vertex, 2> line =
                        {
                                sf::Vertex(sf::Vector2f(1, 0), sf::Color::Green),
                                sf::Vertex(sf::Vector2f(1, 100), sf::Color::Green)
                        };

                        window.draw(line.data(), line.size(), sf::Lines, sf::RenderStates::Default);
                }

                {

                        const std::array<sf::Vertex, 2> line =
                        {
                                sf::Vertex(sf::Vector2f(0, 0), sf::Color::Yellow),
                                sf::Vertex(sf::Vector2f(100, 0), sf::Color::Yellow)
                        };

                        window.draw(line.data(), line.size(), sf::Lines, sf::RenderStates::Default);
                }

                {

                        const std::array<sf::Vertex, 2> line =
                        {
                                sf::Vertex(sf::Vector2f(0, 1), sf::Color::Blue),
                                sf::Vertex(sf::Vector2f(100, 1), sf::Color::Blue)
                        };

                        window.draw(line.data(), line.size(), sf::Lines, sf::RenderStates::Default);
                }

                window.display();
 

4
General / Re: Creating a wrapping game world
« on: January 01, 2015, 11:45:30 pm »
Actually this won't work because the game world could be huge.

5
General / Re: Creating a wrapping game world
« on: January 01, 2015, 11:40:14 pm »
Thanks for your suggestions.

I will make sure to handle the collisions etc, I am just doing the graphics right now.

One last question: Is it ok to create sf::RenderTexture objects each frame or should I keep one around as a member and reuse it?

6
Indeed if you use standard containers you will find many of your custom assignment operators and copy constructors disappear.

7
General / Re: Creating a wrapping game world
« on: January 01, 2015, 10:40:02 pm »
Ok I have an idea. Render the game into a texture and then draw the texture a few times for each edge to create the wrapping effect.

Is that a good idea? Is render to texture slow?

8
General / Creating a wrapping game world
« on: December 30, 2014, 01:29:07 am »
Hi
I'm trying to create a game where there are no boundaries to the 2d game world. If you scroll off the left of the map, graphics from the far right hand side will appear.

I thought about using views but I will need at least two views just for the horizontal, in order to draw graphics nearby which internally are far apart.

Any suggestion on how to go about this?

9
Feature requests / Add public typedef to Vector2
« on: December 29, 2014, 08:03:32 pm »
Hi

Could this be added to Vector2 type please?

typedef T type;

I have some general template code, but I'm stuck, because I cannot query the type contained in vector. I would like to do Vector2::type.

Thank you.

10
General / Re: Is it fine to have sf::Font and sf::Text as global
« on: December 29, 2014, 02:46:29 am »
You can get the address of this singleton:

http://stackoverflow.com/questions/270947/can-any-one-provide-me-a-sample-of-singleton-in-c/271104#271104

Why is a singleton a bad idea for a resource manager which stores unchanging resources loaded from disk? I'm not a singleton fanatic, believe it or not, but if there's ever a good use of a singleton, this seems to be the one.

11
General / Re: Is it fine to have sf::Font and sf::Text as global
« on: December 29, 2014, 02:31:50 am »
A singleton is a nicely packaged global variable, which can solve some problems such as creation order. However as far as other design aspects are concerned, they suffer many of the same problems as global variables. So I consider them practically the same. After all, the singleton has a "static" in there somewhere, right?

12
General / Re: Is it fine to have sf::Font and sf::Text as global
« on: December 29, 2014, 02:04:37 am »
What if more than one thing in your program uses the font, won't that way load it into memory multiple times?

This is why I suggest a global repository of non-modifiable resources sourced from disk. Properly managed in such a way that nothing is loaded before main function is called, and everything gets unloaded before the exit of main.. or pass it as a pointer to all your stuff.

I wouldn't make the menu object itself a global variable, which a singleton essentially is. From what I've seen, it doesn't need to store any state at all.

13
General / Re: Is it fine to have sf::Font and sf::Text as global
« on: December 29, 2014, 12:31:04 am »
I'm not sure what you gain by just switching the namespace to a class.

14
General / Re: How to avoid "the white square problem"?
« on: December 28, 2014, 01:40:32 pm »
If you want to use vector, try std::vector<std::unique_ptr<sf::Texture>>. This will ensure textures have an unchanging address when expanding the vector.

15
Network / Re: Sending enumerations in sf::Packet with C++11
« on: December 28, 2014, 02:09:16 am »
You can put them in a source file but you have to explicitly instantiate it for every allowed parameter which is quite restrictive so usually avoided.

Pages: [1] 2