Hello.
i have a little problem with sf::Shape::getTexture().
i want do this because i need get it a texture to class scene because it inherits of sf::Sprite.
then with this code, my app is crashed
Texture = new sf::Texture;
sf::RectangleShape shape;
shape.setFillColor(sf::Color(255,0,0));
shape.setSize(sf::Vector2f(20,20));
shape.setPosition(20,20);
*Texture = *shape.getTexture();
setTexture(*Texture);
How i should do for receive a texture from sf::Shape?
Sorry for my english xDD
You've understood the purpose of that function wrong...
Get the source texture of the shape.
If the shape has no source texture, a NULL pointer is returned. The returned pointer is const, which means that you can't modify the texture when you retrieve it with this function.
If you want the Rectangle as a texture, you'll have to draw it to a sf::RenderTexture and then retrieve the texture. But what are you tried to do anyways?
You can directly draw a Rectangle shape.
Also don't use manual memory management. ;)
Thank you , xD. I failed translating.
I explain to you i am using a sprite manager for work with layers "z" then i am searching use sf::Sprite. I show to you a example.
void SceneManager::Add(Scene *scene){
if(scene->getZ()>i_ZMoreHight) i_ZMoreHight=scene->getZ();//si es mayor la z que la que hay añadimo el nuevo valor
mScenes.push_back(scene);
i_MaxScenes++;
}
-------------
void SceneManager::Update(sf::RenderWindow &window){
for(int z=0;z<=i_ZMoreHight;z++){// layers
for(int i=0;i<i_MaxScenes;i++){ // Number of scenes
if(mScenes[i]->getZ()==z){//
if(isZoomChange==true){//y además se a cambiado el zoom
mScenes[i]->setScale(ZoomScale,ZoomScale);//
}
mScenes[i]->Update();//this is vector<Scene> inherits of sf::Sprite
window.draw(*mScenes[i]);//this is sf::renderwindow
}
}
}
isZoomChange=false;
//cout << "ESCENAS: "<< i_MaxScenes << endl;
}