SFML community forums
Help => Graphics => Topic started by: Chadwell on March 23, 2009, 07:10:07 am
-
Hey, I'm having some issues with the code from the Image and Sprite tutorial. Basically here is my code:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// Load the sprite image from a file
sf::Image Image;
if (!Image.LoadFromFile("sprite.bmp"))
return EXIT_FAILURE;
// Create the sprite
sf::Sprite Sprite(Image);
// Change its properties
Sprite.SetColor(sf::Color(0, 255, 255, 128));
Sprite.SetPosition(200.f, 100.f);
Sprite.SetScale(2.f, 2.f);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Get elapsed time
float ElapsedTime = App.GetFrameTime();
// Move the sprite
if (App.GetInput().IsKeyDown(sf::Key::Left)) Sprite.Move(-100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Up)) Sprite.Move(0, -100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Down)) Sprite.Move(0, 100 * ElapsedTime);
// Rotate the sprite
if (App.GetInput().IsKeyDown(sf::Key::Add)) Sprite.Rotate(- 100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);
// Clear screen
App.Clear();
// Display sprite in our window
App.Draw(Sprite);
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
The only part of the code I changed was the file name for the sprite. If I build this linking sfml-graphics.lib I get an unhandled Access violation at the ReadFromFile() call, and a bunch of jibberish is spit out of the console. If I like with sfml-graphics-d.lib, I get by the image loading part fine, but at the App.GetEvent(Event) call, I get another Access violation unhandled exception.
Am I doing something wrong? Is this a bug? Whats the deal? Thanks a lot for your help.
-
You're probably mixing different configurations (debug / release), or using the wrong libraries (VS2008 instead of VS2005, for example).
-
You're probably mixing different configurations (debug / release), or using the wrong libraries (VS2008 instead of VS2005, for example).
Ahhh, You are right. I was linking in sfml-system.lib, sfml-Window.lib, and sfml-graphics-d.lib. Once I changed system and Window to -d.lib it worked perfectly.
I must ask, since using all of the non-debug libs at the same time didn't work, do the debug libs HAVE to be used if you are compiling with Visual Studio in debug mode? If I missed that in the tutorial I apologize, but if it isn't in there it might be something useful to add.
Thanks a lot for your help!
-
do the debug libs HAVE to be used if you are compiling with Visual Studio in debug mode?
Yes.
If I missed that in the tutorial I apologize, but if it isn't in there it might be something useful to add
Actually, it is explained in the tutorials:
For the Debug configuration, you can link with the debug versions of the libraries, which have the "-d" suffix (sfml-system-d.lib in this case)
I should probably say "you must" instead of "you can" :)
-
do the debug libs HAVE to be used if you are compiling with Visual Studio in debug mode?
Yes.
If I missed that in the tutorial I apologize, but if it isn't in there it might be something useful to add
Actually, it is explained in the tutorials:
For the Debug configuration, you can link with the debug versions of the libraries, which have the "-d" suffix (sfml-system-d.lib in this case)
I should probably say "you must" instead of "you can" :)
Yep, that was the part that confused me, I thought the "can" implied it was an option. That change would make it a lot clearer.
Thanks a lot for your help I appreciate it!