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

Author Topic: Problem with setTextureRect SFML 2.0  (Read 2156 times)

0 Members and 1 Guest are viewing this topic.

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Problem with setTextureRect SFML 2.0
« on: May 13, 2013, 03:04:20 am »
SFML forum,

 Switching over to SFML 2.0 from 1.6.

 The first project is a conversion of one that is working in 1.6.

 Not to bad so far but I'm have a problem with setTextureRect.

 In 1.6 I used:
   switch(num[index])
   {
      case 1:   Numbers.SetSubRect(sf::IntRect(0,0,63,63));   break;
      case 2:   Numbers.SetSubRect(sf::IntRect(64,0,127,63)); break;
      case 3:   Numbers.SetSubRect(sf::IntRect(128,0,191,63)); break;
      case 4: Numbers.SetSubRect(sf::IntRect(192,0,255,63)); break;
   }

 In 2.0 I use:
   switch(index)
   {
      case 1:   Numbers.setTextureRect(sf::IntRect(0,0,63,63));   break;
      case 2:   Numbers.setTextureRect(sf::IntRect(64,0,127,63)); break;
      case 3:   Numbers.setTextureRect(sf::IntRect(128,0,191,63)); break;
      case 4: Numbers.setTextureRect(sf::IntRect(192,0,255,63)); break;
   }

 Here's how I created the sprite in 2.0:
   sf::Texture MyNumbers;
   MyNumbers.loadFromFile("Numbers2.png");
   sf::Sprite Numbers;

 The problem is when index is 1 I get:
  1                          this is correct

 When it's 2 I get:
  2 3                       should be just  2

 When it's 3 I get:
  3 4                      should be just 3

 When it's 4 I get:
  4  ######          should be just 4

 The #s represent some garbage on the screen?
 
 The Numbers2.png file is attached.

Jerryd


[attachment deleted by admin]

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Problem with setTextureRect SFML 2.0
« Reply #1 on: May 13, 2013, 03:31:32 am »
sf::Rect did change a little bit. In 1.6 you would define it the top, left, right, and bottom coordinates. In 2.0 you define your rect with the top and left coordinates, then the width and height. That way one would only have to change the position of the rect with out having to recalculate the other coordinates.
DSFML - SFML for the D Programming Language.

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Problem with setTextureRect SFML 2.0
« Reply #2 on: May 13, 2013, 04:09:00 am »
Jebbs,
 Thanks that worked.

Jerryd