使用只能指针代替裸指针
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
class ImageService {
|
||||
private:
|
||||
sf::Texture texture;
|
||||
std::shared_ptr<sf::Texture> texture = std::make_shared<sf::Texture>();
|
||||
public:
|
||||
ImageService(const std::string& name){
|
||||
texture.loadFromFile(name);
|
||||
texture->loadFromFile(name);
|
||||
}
|
||||
sf::Texture& GetTexture(){
|
||||
std::shared_ptr<sf::Texture> GetTexture(){
|
||||
return texture;
|
||||
}
|
||||
float GetScale(int width, int height){
|
||||
auto imgSize = texture.getSize();
|
||||
auto imgSize = texture->getSize();
|
||||
return std::min(static_cast<float>(width) / imgSize.x, static_cast<float>(height) / imgSize.y);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user