Hello,
You probably know what is the problem of mine: I have a vector of button objects (class). each button contains a rectangleShape and its texture (I know I can use a sprite). the texture appear to be a white rectangle. in the past everything worked but now its not. I know its a pointer problem, but don't know how to fix it, or how to use the puch_back correctly to make it work. here is the class:
void Button::setButton(float x, float y, float w, float h) {
pos = sf::Vector2f(x, y);
size = sf::Vector2f(w, h);
}
void Button::setTexture(string dir, sf::Vector2f s) {
textureDir = dir;
buttonTexture.loadFromFile(textureDir);
button.setTexture(&buttonTexture);
if (!textureLoaded) textureLoaded = true;
}
void Button::setMode(bool m) {
mode1 = m;
modeList.push_back(mode1);
int temp = 0;
for (int i = 0; i < modeList.size(); i++) {
if (modeList[i]) temp++;
}
if (temp != 0) {
buttonMode = true;
}
else {
buttonMode = false;
}
}
bool Button::getMode() {
return buttonMode;
}
void Button::update() {
button.setPosition(pos);
button.setSize(size);
if (dimention == 0) {
texturePos.x += 128;
}
else {
texturePos.x += 0;
}
if (buttonMode) {
texturePos.y = 64;
}
else {
texturePos.y = 0;
}
modeList.clear();
cout << pos.x << " " << pos.y << " , " << size.x << " " << size.y << endl;
button.setTextureRect(sf::IntRect(texturePos.x, texturePos.y, size.x, size.y));
}
sf::RectangleShape Button::getShape() {
return button;
}
void Button::show(sf::RenderWindow &window) {
window.draw(button);
}
and the buttons are controlled by another class that maneges everything in the current level of the game (probably the issue occures in this function, because it's the only one that related to the buttons except for a functions to change the mode of the button when clicked, and I am not calling this one anywhere in the code):
void Level::newButton(float x, float y, float w, float h, string dir) {
button1.setButton(x * tileSize.x, y * tileSize.y, w * tileSize.x, h * tileSize.y);
cout << "p: " << x << " * " << tileSize.x << " , " << y << " * " << tileSize.y << endl;
button1.setTexture(dir, sf::Vector2f(w, h));
buttonSet.push_back(move(button1));
cout << "New Button Added" << endl;
}
and it is also important to say that you can see the texture on the button in the first frame, but after that it becomes white.
From what I knwo I may want to create a vector of pointers, but I don't know how to do it.
any help will be appreciated,
Arad.