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

Pages: [1]
1
Graphics / Re: How to change pixels on a big map
« on: April 14, 2017, 06:47:15 pm »
I think it looks too complicated to construct a polygon shape for each country wich fits exactly like the country's shape on the map. I started to do an approximative polygon of vertex array for mouse-detection for few countries and it took a lot of time to put each vertex at the correct position. So i don't imagine with an almost perfect polygon to draw a country.

2
Graphics / Re: How to change pixels on a big map
« on: April 14, 2017, 06:33:59 pm »
Yes you're right but if I overlay with a sprite of country, it won't take so many extra time to assign a texture to a country with this sprite. It's almost what I am doing : I am making a texture for many countries and then I'll put them over the big map so I'll keep the little countries I've not made. Actually I just started and doing a texture for each country is not so long and it will probably simplify my code.

Anyway thank you for your answer ; )

3
Graphics / Re: How to change pixels on a big map
« on: April 14, 2017, 03:58:23 pm »
Thank you Uroboro for your answer.

I already thought to do this way at the begining of my project. It is really easier in the use. But i gave up for some reason :
  • It's a hard work to do each texture and put each sprite correctly
  • What can I do of countries that I don't want to implement ? I have a restricted time to do the game and I don't want to put all the countries of the world

However, after a reflexion, I think I'll go this way. I will get the texture of each country with the Photoshop's magical wand tool and it will be much easier to use it in the code than what I started to do (I started to do a vertex-array (triangle strip) for each country to do an approximate shape and then detect if the mouse is over this shape by detecting if the mouse is over one of the triangles of the triangle strip ...) It'll be faster to take the texture with the Wand than writing the coordinates of each vertex of the country's shape. So thank you for your help ! =)

I still hope someone can find an other solution using the map texture, it could save me a lot of time.

4
Graphics / [SOLVED] How to change pixels on a big map
« on: April 14, 2017, 12:26:35 pm »
Hi,

I’m working on a game project. The game is a Quizz where a name of a country appear on the screen and you have to click on the right country on a map.

I’m having trouble with a module of my game : I want that when your mouse is passing over a country, it changes its color, and when the country is found, its color is green etc.
Here is a pic to demonstrate what i’ve achieved (the mouse is over the France) :



Here is how my program works :
•   Each country has a pixel array in the Country class :
std::vector<sf::Vector2u> PixelsArray
It is charged at the start of the game using a Boundary-Fill-like algorithm.
The pixel array countains the position of each pixel of the country.

•   When the mouse is over a country, a fonction in the Map class is called.
Here is how it works :
void Map::fill(std::vector <sf::Vector2u>& pixelsArray, sf::Color newColor)
{
        //Exit the function if we fill with the color of the boundaries
        if (newColor == borderColor)
                return;

        for (int i = 0; i < pixelsArray.size(); i++)
                imageMap.setPixel(pixelsArray[i].x, pixelsArray[i].y, newColor);

        texture.loadFromImage(imageMap);
        map.setTexture(texture);
}
I use an image of the map to transform the pixels and then i am updating the texture of map’s sprite with this image.


The problem is that my map is 3958 * 2596 and it takes about a second to update the texture. So each time i move my mouse over a country, when it wants to update the color to the selected color, my game freeze for one second. I noticed that it doesn’t come from the pixel Array loop but more from the part :
texture.loadFromImage(imageMap);
map.setTexture(texture);

I've tried to reduce the Map's texture to what the player is able to see (the view) so it is by exemple 1700*1050 when the player is on the Europe continent, but it's too slow too.

I've thinked about update texture with :
void sf::Texture::update        (       const Uint8 *   pixels,
unsigned int    width,
unsigned int    height,
unsigned int    x,
unsigned int    y
)      

but it would be very difficult to set an IntRect for each country etc.

Actually what could be perfect, is to use something like
void sf::Texture::update        (       const Uint8 *   pixels  )
with the position of each pixels (wich I already have). In other words, updating the texture with only the pixels of a country (with my country's sf::Vector2u pixel array)

Thank you for your attention, I hope you will understand : P

Pages: [1]
anything