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

Author Topic: Passing sheetRect to a function  (Read 3674 times)

0 Members and 1 Guest are viewing this topic.

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Passing sheetRect to a function
« 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

Raynobrak

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Passing sheetRect to a function
« Reply #1 on: August 11, 2020, 08:06:16 am »
Looks like you forgot to set your IntRect width and height.

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Passing sheetRect to a function
« Reply #2 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

 

anything