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

Pages: 1 2 [3] 4
31
SFML projects / Re: [POLL] Name This Game
« on: February 23, 2016, 01:20:29 am »
World War Pixel.

32
Graphics / Re: Moving camera causes graphic glitch. My investigation.
« on: February 19, 2016, 01:57:34 am »
Since Opengl 2.0 it's not necessary to use power of 2 textures.

33
Graphics / Re: Moving camera causes graphic glitch. My investigation.
« on: February 18, 2016, 03:53:17 pm »
It looks like you're scaling those textures to a non-power of two. If you're scaling (up or down), if the scale factor is not doubling or halving, the pixels are distributing unevenly.
Consider setting your scaling to a power of two, trying turning on smooth for the texture, or render to a render texture and then scale that (possibly with smooth).

I found also this info: http://gamedev.stackexchange.com/questions/58195/sfml-fail-to-load-image-as-texture

Quote
OpenGL does not like loading in textures that are not to the power of 2, some loaders add padding to make up to these numbers, but you cannot account for all libraries you use to achieve this. Try scaling the image to 512x512 as opposed to 510x510 and change 125 to 128, usually the texture will load in this instance in graphics libraries and you will experience tearing and distortion across the surface of the model, as it moves in relation to the view port.


Does it mean that when I load textures I must use images always with power of 2? In my case the tileset texture have this size 144x80, if the above info it's true I must change the texture size to 256x128. Isn't it?

Does SFML solve the OpenGl problem?

34
Graphics / Re: Moving camera causes graphic glitch. My investigation.
« on: February 18, 2016, 03:02:45 am »
Thank you. That was the solution, I was scaling the map by 2.6 and I changed to 2.

I imagined that I was calculing the scale badly, just a 20 seconds thought. Probably I couldn't find the solution by myself.

35
Graphics / Moving camera causes graphic glitch. My investigation.
« on: February 18, 2016, 01:35:28 am »
I use SFML-2.3.2-windows-vc14-32-bit in Visual Studio 15. It happens in my PC and in my laptop. Look to the brick joints, when I move the character the joints changes the widths. Look the picture, different sizes.



And video in movement:



 

This not happens when I resize the window manually. That could be a clue. Only making the window bigger in the resize.



Look the tile map in Tiled. It not happens only in the edges of the tile because. The joints are where it's more visible but there areanother  pixels that changes width.










It seems like a graphics glitch but maibe it's the way I set the textures and the positions. ¿Precision problem? Here you have my code where I set the Quads of each tile.

std::vector<int> map = all_map[layer_id];
        LayerObject layer;
        layer.texture.loadFromFile(spritesheet);
        layer.entity_vertex.setPrimitiveType(sf::Quads);
        layer.entity_vertex.resize(width * height * 4); // Each tile have 4 vertex
        layer.layer_id = layer_id;
        //sf::Vector2u TS(tmx_info.tile_size.x, tmx_info.tile_size.y); //TILE_SIZE
       
        sf::Vector2u TS(16, 16); //TILE_SIZE

        for (unsigned int i = 0; i < height; ++i)
        {
                for (unsigned int j = 0; j < width; ++j)
                {
                        unsigned int tile_pos = j + i*width;
                        unsigned int tile_texture_num = 0;

                        //TR = Tile Row // TC =Tile column
                        unsigned int TR = map[tile_pos] / (layer.texture.getSize().x / TS.x); //TILE_ROW
                        unsigned int TC = ((map[tile_pos]) % (static_cast<int>(layer.texture.getSize().x / TS.x))); //TILE_COLUMN

                        sf::Vertex* quad = &layer.entity_vertex[tile_pos * 4];


                        quad[0].position = sf::Vector2f( j * TS.x ,      i * TS.y);
                        quad[1].position = sf::Vector2f((j + 1) * TS.x,  i * TS.y);
                        quad[2].position = sf::Vector2f((j + 1) * TS.x, (i + 1) * TS.y);
                        quad[3].position = sf::Vector2f( j * TS.x ,     (i + 1) * TS.y);
                       
                       
                        quad[0].texCoords = sf::Vector2f( TC * TS.x ,       TR * TS.y );
                        quad[1].texCoords = sf::Vector2f((TC + 1) * TS.x ,  TR * TS.y );
                        quad[2].texCoords = sf::Vector2f((TC + 1) * TS.x , (TR + 1) * TS.y);
                        quad[3].texCoords = sf::Vector2f( TC * TS.x ,      (TR + 1) * TS.y);
                       
                }
        }

       
        map_layers.push_back(layer);


36
When there is only one key I use this function to check when one key is released:

if (GameApp::event.type == sf::Event::KeyReleased && GameApp::event.key.code == sf::Keyboard::Right)
{

}
 

But when there are two keys pressed at the same time and I release one the event it's not handled.


PD: Sorry it's solved, the code works but I was checking inside a function that it's executed only when a key it's pressed so  I wrote again the function.

37
General / Re: Converting an object from global to local space
« on: January 19, 2015, 10:43:42 pm »
I don't know exactly what do you want to do but usually you need the global transform to handle collision for example.

Look  getGlobalBounds() function.


38
General / Re: Separating axis theorem: Circle and rodated square
« on: January 19, 2015, 08:07:00 pm »
Ok, I find the  two points of the perimeter using trigonometry and I proyect it in each axis, but I fail. The collision is produced but in 2 quadrant you can enter inside the circle a little and in the other 1 the collsion is is a little bit outside. In the north east quadrant the collision is produced too many pixels outside.

PD: Sorry, works fine thank you.  :)

float findAngle(sf::Vector2f v)
{
        return atan(v.y/ v.x);
}

bool satBoxCircle(const sf::RectangleShape& object1, const sf::CircleShape& object2)
{
        sf::Vector2f Points[4];
        Points[0] = object1.getTransform().transformPoint(0.f, 0.f);
        Points[1] = object1.getTransform().transformPoint(object1.getSize().x, 0.f);
        Points[2] = object1.getTransform().transformPoint(object1.getSize().x, object1.getSize().y);
        Points[3] = object1.getTransform().transformPoint(0.f, object1.getSize().y);
        sf::Vector2f circle_center(Object2.getPosition().x + object2.getRadius(), object2.getPosition().y + Object2.getRadius());
       
        //Find nearest square vertex to the circle center
        int index = 0;
        float min_distance = distance(Points[0], circle_center);
        for (int i = 0; i < 4; i++)
        {
                if (distance(Points[i], circle_center) < min_distance)
                {
                        min_distance = distance(Points[i], circle_center);
                        index = i;
                }
        }

        sf::Vector2f Axis[3] = {
                sf::Vector2f(Points[1].x - Points[0].x, Points[1].y - Points[0].y),
                sf::Vector2f(Points[1].x - Points[2].x, Points[1].y - Points[2].y),
                sf::Vector2f(Points[index].x - circle_center.x, Points[index].y - circle_center.y)
        };

       

        //Project each point into each axis and find min and max
        for (int i = 0; i < 3; i++)
        {
                float box_min = 0.f, box_max = 0.f;
                box_min = dotProduct(Points[0], Axis[i]);
                box_max = box_min;

                for (int j = 0; j<4; j++)
                {
                        float projection = dotProduct(Points[j], Axis[i]);
                        if (projection<box_min) box_min = projection;
                        if (projection>box_max) box_max = projection;
                }

                float circle_min = 0.f, circle_max = 0.f;
                sf::Vector2f point_perimeter1(circle_center.x - Object2.getRadius()*cos(findAngle(Axis[i])), circle_center.y - Object2.getRadius()*sin(findAngle(Axis[i])));
                sf::Vector2f point_perimeter2(circle_center.x + Object2.getRadius()*cos(findAngle(Axis[i])), circle_center.y  + Object2.getRadius()*sin(findAngle(Axis[i])));
               
                float circle_1_projection = dotProduct(point_perimeter1, Axis[i]);
                float circle_2_projection = dotProduct(point_perimeter2, Axis[i]);

                if (circle_1_projection < circle_2_projection)
                {
                        circle_min = circle_1_projection;
                        circle_max = circle_2_projection;
                }
                else
                {
                        circle_min = circle_2_projection;
                        circle_max = circle_1_projection;
                }

                if (!((circle_min <= box_max) && (circle_max >= box_min)))
                        return false;
        }
       
        return true;

}
 

39
General / Separating axis theorem: Circle and rotated square
« on: January 19, 2015, 04:02:34 pm »
In one tutorial I've found on the internet tells that I must project the center of the circle into the 3 axis, 2 axis will be from the square and one is the vector from the center of the circle to the nearest point of the square.

My problem it's that I don't know how to add the radius to the center proyection. Now the rectangle collides only with the circle center but I don't know how to collide the perimeter.

http://www.sevenson.com.au/actionscript/sat/



bool satBoxCircle(const sf::RectangleShape& object1, const sf::CircleShape& object2)
{
        sf::Vector2f Points[4];
        Points[0] = object1.getTransform().transformPoint(0.f, 0.f);
        Points[1] = object1.getTransform().transformPoint(object1.getSize().x, 0.f);
        Points[2] = object1.getTransform().transformPoint(object1.getSize().x, object1.getSize().y);
        Points[3] = object1.getTransform().transformPoint(0.f, object1.getSize().y);
        sf::Vector2f circle_center(object2.getPosition().x + object2.getRadius(), object2.getPosition().y + object2.getRadius());

        //Find nearest square vertex to the circle center
        int index = 0;
        float min_distance = distance(Points[0], circle_center);
//Proyect square
        for (int i = 0; i < 4; i++)
        {
                if (distance(Points[i], circle_center) < min_distance)
                {
                        min_distance = distance(Points[i], circle_center);
                        index = i;
                }
        }

        sf::Vector2f Axis[3] = {
                sf::Vector2f(Points[1].x - Points[0].x, Points[1].y - Points[0].y),
                sf::Vector2f(Points[1].x - Points[2].x, Points[1].y - Points[2].y),
                sf::Vector2f(Points[index].x - circle_center.x, Points[index].y - circle_center.y)
        };

        //Proyect each point into each axis and find min and max
        for (int i = 0; i < 3; i++)
        {
                float box_min = 0.f, box_max = 0.f;
                box_min = dotProduct(Points[0], Axis[i]);
                box_max = box_min;

                for (int j = 0; j<4; j++)
                {
                        float projection = dotProduct(Points[j], Axis[i]);
                        if (projection<box_min) box_min = projection;
                        if (projection>box_max) box_max = projection;
                }

                float circle_center_projection = dotProduct(circle_center, Axis[i]);
                if (!((circle_center_projection <= box_max)) && (circle_center_projection >= box_min)) return false;
        }
       
        return true;
}
 

40
SFML projects / Re: Moonman (my sfml game is on kickstarter!)
« on: January 17, 2015, 04:24:49 pm »
Hei!! Good job.

As you i'm working in a game. I have been programming one year in order to make a kickstarter in the future. It will be an action rpg but I don't want to make any presentation because I'm using graphics that are not mine and i must work more in scripting, enemys and particles, when I finish the demo with a town and a dungeon and final boss i will publish it in forums to get feedback and then make the kickstarter.


41
Graphics / Re: Modify a VertexArray in game
« 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.

42
Graphics / 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);

                        }
                }
        }




43
General discussions / Re: SFML 2.2 Released!
« on: December 19, 2014, 03:02:34 pm »
The effects that Google Chrome do on the sf::sleep function has been solved :)

44
General discussions / Re: SFML Game Development -- A book on SFML
« on: December 16, 2014, 02:59:04 pm »
I found the solution. Instead of returning the value in the recursive function I use an auxiliar node to store the value and returning it. If it's not found there is an assertion.


template <typename T>
T* getNode(std::string c_key)
{
        SceneNode *aux_node = nullptr;
        findNode(c_key, aux_node);
        assert(aux_node != nullptr);
        return static_cast<T*>(aux_node);
}

void SceneNode::findNode(std::string c_key, SceneNode *&aux)
{
    if (c_key == this->getKey()) aux = this;
        for (auto& itr : children) itr->findNode(c_key, aux);
}
 

Then I call the function:

scene_graph->getNode<Enemy>("Nosferatu")


   

45
General discussions / Re: SFML Game Development -- A book on SFML
« on: December 15, 2014, 02:45:23 am »
I'm using the structure of the book to make games, I already Programmed a Pacman.

I want to find nodes by "key" in scene_graph. I need it for scripting and program the quest system of an action rpg. My problem I think it's that I don't understand recursion, i'm not sure if I can return a node.


template<typename T>
T* findNode(std::string c_key)
{
        if (c_key == key)
        {
                return (static_cast<T*>(this));
        }

        for (auto &itr : children)
        {
                itr->findNode<T>(c_key);
        }

                       
}

Then I call the function and it fails, I get the error typical when acceding to a method of an object pointing to null:

scene_graph->findNode<Enemy>("dog01")->getHp();

The problem it's the returning node because inside the find function the search works and I can get info. I feel like I'm not returng the value in the correct way.

If I check the info inside the find function for each entity it tells the info correctly.

if (c_key == key)
{
 std::cout << "Info" << (static_cast<T*>(this))->getHp() << std::endl // Works for each enemy
return (static_cast<T*>(this));
}

                       

Pages: 1 2 [3] 4
anything