SFML community forums

Help => Window => Topic started by: jerryd on August 10, 2020, 09:15:34 pm

Title: Passing sheetRect to a function
Post by: jerryd on August 10, 2020, 09:15:34 pm
SFML forum,
 I think this would related to a window problem.

 I'm using the sheetRect command successfully in the main flow of my program
 but when I pass it to a function it is grayed out and doesn't work.  The
 compiler doesn't complain and everything runs Ok.

here's the function declaration:
void drawToWindow(sf::RenderWindow &window, sf::IntRect &sheetRect);

here's the function call:
  drawToWindow(window, sheetRect);

here's the function:
void drawToWindow(sf::RenderWindow &window, sf::IntRect &sheetRect)
{
   sheetRect.top = 0;
   sheetRect.left = 0;
   suits.setTextureRect(sheetRect);
   suits.setPosition(50,1);

   window.clear(sf::Color::Green);
   window.draw(suits);
   window.draw(text);
   window.display();
}

The window commands work but not the sheetRects are grayed out?
As I stated this all works outside of the function.

jerryd
Title: Re: Passing sheetRect to a function
Post by: Raynobrak on August 11, 2020, 08:06:16 am
Looks like you forgot to set your IntRect width and height.
Title: Re: Passing sheetRect to a function
Post by: jerryd on August 11, 2020, 08:20:06 pm
Raynobrak,
 Definitely have the sheetRect sizes set.

 I discovered I was passing the sprite wrong.

 Didn't see a way to mark this as "Solved".

 Thanks for the reply.
jerryd