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

Author Topic: setTextureOffset() / offsetTexture()  (Read 3584 times)

0 Members and 2 Guests are viewing this topic.

TestZombie

  • Newbie
  • *
  • Posts: 11
    • View Profile
setTextureOffset() / offsetTexture()
« 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.


dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: setTextureOffset() / offsetTexture()
« Reply #1 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?

TestZombie

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: setTextureOffset() / offsetTexture()
« Reply #2 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*
« Last Edit: June 02, 2015, 12:18:53 am by TestZombie »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: setTextureOffset() / offsetTexture()
« Reply #3 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.
Laurent Gomila - SFML developer