SFML community forums

General => Feature requests => Topic started by: TestZombie on June 01, 2015, 04:38:29 am

Title: setTextureOffset() / offsetTexture()
Post by: TestZombie on June 01, 2015, 04:38:29 am
used:
// works like setPosition()
Sprite.setTextureOffset(float xOffset, float yOffset);
Sprite.setTextureOffset(/*vectorthing*/);

// works like move();
Sprite.offsetTexture(float xOffset, float yOffset);
Sprite.offsetTexture(/*vectorthing*/);
 

Basically, it would move the texture within the sprite's box. When the Texture is set to loop, it would still repeat within the Sprite.

a major use of this:
Parallax: set the sprite with the background texture (looping), equal to the size of the view, and centered on the player. then each frame call
Sprite.offsetTexture(PlayerX / SomeNumber, PlayerY / SomeNumber);
for each level of parallax, have a different SomeNumber variable to change individual level speeds.

Title: Re: setTextureOffset() / offsetTexture()
Post by: dabbertorres on June 01, 2015, 06:30:52 am
This may be a bit naive, but doesn't sf::Sprite::setTextureRect accomplish pretty much the same thing?
Title: Re: setTextureOffset() / offsetTexture()
Post by: TestZombie on June 01, 2015, 07:29:44 am
This may be a bit naive, but doesn't sf::Sprite::setTextureRect accomplish pretty much the same thing?
setTextureRect would never loop, it's basically a view for the texture*
Title: Re: setTextureOffset() / offsetTexture()
Post by: Laurent on June 01, 2015, 07:33:38 am
That's what sf::Sprite is, a view for a texture. Whatever you do with the sprite, you'll need to set the texture in repeat mode if you want it to loop (texture.setRepeated(true)), and once you've done that, sprite.setTextureRect is all you need.