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

Author Topic: RenderWindow draws white sprites  (Read 3965 times)

0 Members and 1 Guest are viewing this topic.

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
RenderWindow draws white sprites
« on: January 16, 2010, 09:34:21 pm »
How come when I'm drawing sprites on my RenderWindow they come up as white? I'm on Windows, and SFML 1.5.

Any ideas?

Here is some loading and drawing code:
Code: [Select]

void Board::LoadContent()
{
sf::Image boardImage;
boardImage.LoadFromFile("data/board.png");
boardTexture = sf::Sprite(boardImage);
tileSize = boardTexture.GetSize().x / BOARDSIZE;

sf::Image pieceSetImage;
pieceSetImage.LoadFromFile("data/jewels.png");
pieceSet.SetImage(pieceSetImage);
}

void Board::Draw()
{
renderWindow.Draw(boardTexture);
renderWindow.Draw(pieceSet);
}


If anyone could help me that would be great :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderWindow draws white sprites
« Reply #1 on: January 16, 2010, 09:56:26 pm »
The images are local to the LoadContent function, thus they are destroyed when it exits, and your sprites point images that no longer exist.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
RenderWindow draws white sprites
« Reply #2 on: January 16, 2010, 11:23:15 pm »
The solution is to make the images member variables of your class Board. Furthermore, you should check loading errors and forward them to the caller, for instance by letting LoadContent() return a bool.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
RenderWindow draws white sprites
« Reply #3 on: January 17, 2010, 01:47:34 am »
How do I make member variables in a class?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
RenderWindow draws white sprites
« Reply #4 on: January 17, 2010, 04:44:50 am »
Quote from: "YellowShadow"
How do I make member variables in a class?
You should really learn the C++ basics before you begin to use a high-level framework like SFML. Classes and object-oriented programming is one of the things you must know at C++.

Don't get me wrong, but you'll continuously run into trouble if you are lacking essential knowledge. Especially C++ is a language which isn't easy at all, and which offers a lot of pitfalls for people not used to it. It's really worth the time to learn some theory before developping games. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
RenderWindow draws white sprites
« Reply #5 on: January 17, 2010, 05:19:19 am »
Yea, I'm gonna pick up a book or something and learn C++.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
RenderWindow draws white sprites
« Reply #6 on: January 17, 2010, 01:56:00 pm »
I can recommend the C++ Primer. Or Thinking in C++, which is also available as free e-book.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

YellowShadow

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - ehwatsupdoc21
    • View Profile
RenderWindow draws white sprites
« Reply #7 on: January 17, 2010, 05:10:11 pm »
Thanks! I'll check those out :)