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.


Topics - marCOmics

Pages: [1]
1
Hallo again SFML community,

I ran into another problem. I made a project that starts in a window where multiple mini games are displayed, from which you can choose from which to start. Depending on the the game which is selected I wanted to resize the existing window through using the .setSize(sf::Vector2()) function.
But everything gets stretched with it, is there a way to prevent this (Except opening up a whole new window and shutting the old one down)?

Thanks in advance, I hope this wasn't asked already.

2
General / Question about life time of sf::Texture
« on: May 27, 2017, 11:38:21 pm »
 ;DHello everybody,

first post by me.

In my project, I have a class that should handle Sprites that are made of a pixel array.
The class has a vector of Sprites, which is looped over and the individual Sprites should be drawn every update cycle. Now I made a method that creates new sprites of the pixel array and pushes them onto the vector.

sth like this (shortened pseudocode version):
Quote from: pseudecode

void CSpriteHandleClass::createButton(/*params*/){
sf::Image image;
sf::Sprite sprite;
sf::Texture texture;

//create UInt8 pixel array & fill it
//create image from the pixel array
//set texture from the image
//set sprite from the texture

global_spritevector.push_pack(sprite);

}

(in main it loops over the vector and draws every sprite)


When I then run the code, everything seemed okay except that the texture of the sprite had no color (it should've been red, as I filled it that way). I found out, that if I declare the Texture in the pseudocode as a pointer (sf::Texture* texture = new sf::Texture) it would work and the colors showed up.

I guess the Sprite is only storing a pointer to the texture which dies when getting out of the scope (method)?

But why does the Sprite itself live on and the Texture not? They should both be copied into the vector I thought, so technically even as a non-pointer the data should be there, doesn't it?? I looked up the reference (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Texture.php#details) but except "it lives in the graphics card" nothing regarding the life time of the texture object is said. I'm really confused, would love if someone could help me understand whats going on.

Greetings!


Pages: [1]