Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: i have a little proble with sf::Shape::getTexture().  (Read 1668 times)

0 Members and 1 Guest are viewing this topic.

exafi

  • Newbie
  • *
  • Posts: 41
    • View Profile
i have a little proble with sf::Shape::getTexture().
« on: March 26, 2013, 11:37:34 pm »
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

« Last Edit: March 26, 2013, 11:39:05 pm by exafi »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: i have a little proble with sf::Shape::getTexture().
« Reply #1 on: March 27, 2013, 12:01:20 am »
You've understood the purpose of that function wrong...

Quote
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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

exafi

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: i have a little proble with sf::Shape::getTexture().
« Reply #2 on: March 27, 2013, 12:12:08 am »
You've understood the purpose of that function wrong...

Quote
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;
}
« Last Edit: March 27, 2013, 12:16:35 am by exafi »

 

anything