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

Author Topic: Modify a VertexArray in game  (Read 1283 times)

0 Members and 1 Guest are viewing this topic.

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Modify a VertexArray in game
« on: January 05, 2015, 03:30:33 am »
The problem is that when a modify a vertexarray the modifications are in the bottom layer and the object that I want to refresh remains in the top layer.

This is a code of an animation, it works but if I put it in the same position of another quad it will be covered by the static object that i want to modify.



for (auto &itr1 : tiled_map_animations)
        {
                for (auto &itr2 : ids)
                {
                        if (tmx_info.maps[2][itr2]+ 4 == itr1.first)
                        {      
               
                                sf::Vertex* quad = &map_layers[2].entity_vertex[itr1.first * 4];

                                float x = itr1.second[current_anim].left;
                                float y = itr1.second[current_anim].top;

                                float w = itr1.second[current_anim].width;
                                float h = itr1.second[current_anim].height;
                                float pos_x = (itr2 % map_width) * tile_width;
                                float pos_y = (itr2 / map_width) * tile_height;

                                quad[0].texCoords = sf::Vector2f(x, y);
                                quad[1].texCoords = sf::Vector2f(x + w, y);
                                quad[2].texCoords = sf::Vector2f(x + w, y + h);
                                quad[3].texCoords = sf::Vector2f(x, y + h);

                                quad[0].position = sf::Vector2f(pos_x, pos_y);
                                quad[1].position = sf::Vector2f(pos_x + w, pos_y);
                                quad[2].position = sf::Vector2f(pos_x + w, pos_y + h);
                                quad[3].position = sf::Vector2f(pos_x, pos_y + h);

                        }
                }
        }




Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Modify a VertexArray in game
« Reply #1 on: January 05, 2015, 03:35:22 am »
Ok it's solved, the index of the array was different than the object to modify. 4 hours dealing with this and solved it 3 minutes after posting, perfect.