sf::Texture as class member doesn't work?

半腔热情 提交于 2019-11-27 16:14:16

This is called the white square problem.

Basically, at some point, your object is copied but the copy constructor doesn't update the copied sprite texture to use the copied texture, and the original texture is destroyed so the copied sprite doesn't have a valid texture anymore.

A quick fix can simply run the initialisation code inside the copy constructor and copy assignment operator.


BTW

myimg_texture.create(icon.width, icon.height);
myimg_texture.update(myimg_image);

can directly use icon.pixelData instead of myimg_image and thus you don't need an sf::Image at all.

Or you can do as follow if you need the sf::Image for another purpose:

myimg_texture.loadFromImage(myimg_image);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!