0

I'm trying to create a calculator in c++ using SFML library. To make the buttons, I've created a array of rectangles sf::RectangleShape buttons[16] then I downloaded some textures to put on this rectangles. I used

float x_pos =24.f, y_pos=282.f;
int k=0,limit = 4;
for(int i=0; i<4; i++)
    {
        for (int j=k;j<limit;j++)
        {
            this->buttons[j].setPosition(x_pos,y_pos);
            this->buttons[j].setSize(sf::Vector2f(74.f,74.f));
            this->buttons[j].setTexture(&this->texture[j],false);
            x_pos+=148.f;
        }
        
        k=limit;
        limit+=4;
        x_pos=24.f;
        y_pos+=148;
    }

to initialize the buttons and this

//Textures
    std::stringstream ss;
    for(int i=0; i<10; i++)
    {
        ss << "Texturesa/" << i << ".png";
        this->texture[i].loadFromFile(ss.str());
        ss.str().clear();
    }

to load textures in another array (of textures). But when I start the program, I get this: I see the first texture only

This is the render function if it's useful:

void Calcolatrice::render()
{
    this->window->clear();
    this->window->draw(this->input); this->window->draw(this->output);
    for (int j=0; j<16;j++)
    {
        this->window->draw(this->buttons[j]);
    }
    this->window->display();
}
m05
  • 11
  • 1

0 Answers0