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

Pages: [1]
1
Window / Window style
« on: February 17, 2020, 07:33:05 pm »
How can I change style of the Window, after creation?

I have a sf::RenderWindow mainWindow; variable in my game class, and I want change style after creation.

thx in advance 4 ur attention

2
Graphics / Re: Vector of structs which contains sprites
« on: February 08, 2020, 10:43:00 pm »
1. "U could, as another example, pushing into the vector after u set the sprite."
When I do that - all sprites are turning to white -> because ui.back().sprite cant find texture -> because ui.back().sprite thinking that texture is in uiElement btn; but when i draw ui.back().sprite  uiElement btn; is didnt exist already.

I tried to do that before, so next step was add to std::vector<uiElement> ui; btn only with texture, then assign that texture to sprite and ui.back().sprite would link texture not from uiElement btn; but from ui.back().texture.
Aaaand that didn't work((

2. " make ur vector of pointers (uiElement*)"
At first - I initialize all elements in my class constructor. And if i use pointers - will my alements exist in memory after my constructor?
At second - I dont learn yet how to work with memory(((

3. "rather than using back(), get the address of the last element in vector"

I tried and changed my for:

for (int i = 0;i < 4;i++){
                    uiElement btn;
                    btn.texture.loadFromFile("../res/textures/button.png");
                    ui.push_back(btn);
                    Texture* t_ptr = &ui.back().texture;
                    ui[ui.back()].sprite.setTexture(*t_ptr);
}


And result was the same(( Only last button has correct texture and sprite,  the other are white(

3
Graphics / Vector of structs which contains sprites
« on: February 08, 2020, 01:44:41 am »
Im trying to do a vector of struct elements to draw them in RenderWindow;

my struct for non-ui objects:

struct element{
    sf::Texture texture;
    sf::Sprite sprite;
    sf::IntRect rect;
    sf::Text text;
};


my struct for ui objects:

struct uiElement: element{
    sf::Text text;
    bool clickable;
};


Im adding elements like that:

std::vector<uiElement> ui;

uiElement el;

el.texture.loadFromFile("../res/textures/background.jpg");
ui.push_back(el);
ui.back().sprite.setTexture(ui.back().texture);


and it works!But, only if my "std::vector<uiElement> ui;" has one element;

when i try to add more with cycle:

for (int i = 0;i < 4;i++){
                    uiElement btn;
                    btn.texture.loadFromFile("../res/textures/button.png");
                    ui.push_back(btn);
                    ui.back().sprite.setTexture(ui.back().texture);
}


draws only last object in my "std::vector<uiElement> ui;" and the other are just white

my drawing part of code:

for (auto & element : ui){
        window.draw(element.sprite);
}


How can I fix it??

thanks in advance :)

Pages: [1]