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

Author Topic: sf::Sprite changing a sprite problem  (Read 1584 times)

0 Members and 1 Guest are viewing this topic.

Canvas

  • Full Member
  • ***
  • Posts: 107
    • View Profile
sf::Sprite changing a sprite problem
« on: June 24, 2012, 04:09:32 am »
Hey guys, im just testing out the sf::Sprite, now at the moment my code uses a simple image manager to load a image, it then sets the sprite of a class, so for example
item.cpp has a public variable sf::Sprite spriteImg;
so i then call item1.spriteImg.setTexture(imgManage.get_image("imgArgh.gif"),
now this is the code I have for its update, which is called when the player presses space
      sf::IntRect temp = sprite.getTextureRect();
      pos.h = temp.height; //66
      pos.w = temp.width; //66
      sprite.setTextureRect(temp);
Now this just sets up the correct height and width.
That works all fine and well but, if i then do this for example
item1.spriteImg.setTexture(imgManage.get_image("circle.gif"),
this code then executes
      sf::IntRect temp = sprite.getTextureRect();
      pos.h = temp.height; //32
      pos.w = temp.width; //32
      sprite.setTextureRect(temp);
My circle image is set to 66 width and 66 height...

What am I doing wrong? I would try and reset the sf::Sprite but there doesn't seem to be a function.

Cheers

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: sf::Sprite changing a sprite problem
« Reply #1 on: June 24, 2012, 05:42:29 am »
You can use the setScale functions to change the size.

And you can reset an object to it's default state by assigning it to a new object of the same type.

    sprite = sf::Sprite(); // reset dirty to it's default state

Your post is hard to understand, so I'm not sure whether this is the information you were looking for.

Canvas

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: sf::Sprite changing a sprite problem
« Reply #2 on: June 24, 2012, 04:46:29 pm »
Its ok, i messed around with setting a new sprite up and setScale and i sorted it :) cheers for the help
« Last Edit: June 24, 2012, 05:01:38 pm by Canvas »

 

anything