SFML/ C++ question

sorry for opening another thread i dont know how to bump a thread so i opened another one cause i still didnt get an answer :D
(here is old thread link so u can see what people told me and help me please!)
http://www.cplusplus.com/forum/general/182235/
hey im building a game in sfml/c++
im trying to make void that draws circle in 4 parts at the same place so it looks like drawing effect
example of a box in 4 parts:
1. |

2. |_

3. |_|

4.
__
|_|

this is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
	void drawCircle(sf::RenderWindow & window, int x , int y)
	{
		sf::Texture texture;
		texture.loadFromFile("gamefiles//O.png");
		sf::Sprite circle;
		sf::Clock repeat;
		circle.setPosition(x, y);
		circle.setTexture(texture);
		circle.setTextureRect(sf::IntRect(0, 0, 176, 141));
		int step = 0;
		while (step != 5)
		{
			if (repeat.getElapsedTime().asSeconds() > 0.1)
			{
				circle.setTextureRect(sf::IntRect(0 + (178 * step), 0, 176, 141));
				step++;
				repeat.restart();
			}
			window.draw(circle);
			window.display();
		}
	}



now i have 2 problems:
1.when im doing window.display() on my function void and not on my main void the rest of the code that i wrote in the main void is flashing on a off
2.after the action is done the circle it self deleted at all i know why it happens i just dont have solution

please help me ASAP tnx !
Here's a simple example of how one might do something similar:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <SFML/Graphics.hpp>
#include <vector>

void draw_partial_box(sf::RenderTarget& t, const std::vector<sf::Vector2f>& box, 
                      float time_passed, float target_time)
{
    const float quarter_time = target_time * .25f;

    std::vector<sf::Vertex> v(1, { box[0], sf::Color::Black });

    for (std::size_t i = 0; i < box.size()-1; ++i)
    {
        if (time_passed > quarter_time * i)
        {
            float ratio = 1.0f;

            if (time_passed < quarter_time * (i + 1))
                ratio = 1.0f - (quarter_time * (i + 1) - time_passed) / quarter_time;

            v.push_back({ {(box[i + 1].x - box[i].x)*ratio + box[i].x,
                            (box[i + 1].y - box[i].y)*ratio + box[i].y}, sf::Color::Black });
        }
    }

    t.draw(v.data(), v.size(), sf::LinesStrip);
}

int main()
{
    sf::VideoMode vm(800, 600);

    sf::RenderWindow win(vm, "Boxy");

    std::vector<sf::Vector2f> points =
    {
        { vm.width * .25f, vm.height * .25f },
        { vm.width * .75f, vm.height * .25f },
        { vm.width * .75f, vm.height * .75f },
        { vm.width * .25f, vm.height * .75f },
        { vm.width * .25f, vm.height * .25f }
    };

    sf::Clock clock;
    while (win.isOpen())
    {
        sf::Event event;

        while (win.pollEvent(event))
        {
            switch (event.type)
            {
            case sf::Event::Closed:
                win.close();
                break;
            }
        }

        win.clear(sf::Color::White);

        draw_partial_box(win, points, clock.getElapsedTime().asSeconds(), 5.0f);

        win.display();
    }
}
Last edited on
Topic archived. No new replies allowed.