mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Make Sprite::getTexture return a reference
and do some simplification using the fact that a constructed sprite has a non-null texture pointer.
This commit is contained in:
parent
751aceadf8
commit
623d0f67ea
@ -139,16 +139,15 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the source texture of the sprite
|
||||
///
|
||||
/// If the sprite has no source texture, a null pointer is returned.
|
||||
/// The returned pointer is const, which means that you can't
|
||||
/// The returned reference is const, which means that you can't
|
||||
/// modify the texture when you retrieve it with this function.
|
||||
///
|
||||
/// \return Pointer to the sprite's texture
|
||||
/// \return Reference to the sprite's texture
|
||||
///
|
||||
/// \see setTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture* getTexture() const;
|
||||
const Texture& getTexture() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the sub-rectangle of the texture displayed by the sprite
|
||||
|
@ -55,8 +55,8 @@ Sprite::Sprite(const Texture& texture, const IntRect& rectangle)
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sprite::setTexture(const Texture& texture, bool resetRect)
|
||||
{
|
||||
// Recompute the texture area if requested, or if there was no valid texture & rect before
|
||||
if (resetRect || (!m_texture && (m_textureRect == sf::IntRect())))
|
||||
// Recompute the texture area if requested
|
||||
if (resetRect)
|
||||
{
|
||||
setTextureRect(IntRect({0, 0}, Vector2i(texture.getSize())));
|
||||
}
|
||||
@ -90,9 +90,9 @@ void Sprite::setColor(const Color& color)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture* Sprite::getTexture() const
|
||||
const Texture& Sprite::getTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
return *m_texture;
|
||||
}
|
||||
|
||||
|
||||
@ -130,8 +130,6 @@ FloatRect Sprite::getGlobalBounds() const
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sprite::draw(RenderTarget& target, const RenderStates& states) const
|
||||
{
|
||||
assert(m_texture && "Cannot use null texture. Call Sprite::setTexture() to initialize it.");
|
||||
|
||||
RenderStates statesCopy(states);
|
||||
|
||||
statesCopy.transform *= getTransform();
|
||||
|
Loading…
Reference in New Issue
Block a user