I'm not being able to draw an sf::Image to a sf::RenderWindow.
PlayState.cpp: In member function ‘virtual void PlayState::render()’:
PlayState.cpp:30:34: error: no matching function for call to ‘sf::RenderWindow::draw(sf::Image&)’
PlayState.cpp:30:34: note: candidates are:
In file included from /usr/include/SFML/Graphics/RenderTexture.hpp:33:0,
from /usr/include/SFML/Graphics.hpp:39,
from PlayState.cpp:3:
/usr/include/SFML/Graphics/RenderTarget.hpp:186:10: note: void sf::RenderTarget::draw(const sf::Drawable&, const sf::RenderStates&)
/usr/include/SFML/Graphics/RenderTarget.hpp:186:10: note: no known conversion for argument 1 from ‘sf::Image’ to ‘const sf::Drawable&’
/usr/include/SFML/Graphics/RenderTarget.hpp:197:10: note: void sf::RenderTarget::draw(const sf::Vertex*, unsigned int, sf::PrimitiveType, const sf::RenderStates&)
/usr/include/SFML/Graphics/RenderTarget.hpp:197:10: note: candidate expects 4 arguments, 1 provided
make: *** [all] Error 1
void PlayState::render() {
game->window.clear();
game->window.draw(player->image);
game->window.display();
}
That is my code. First of all, isn't sf::Image an sf::Drawable? Secondly, how would I go about passing the sf::RenderStates?
Thank you.
Oh wait, just read this (http://www.sfml-dev.org/tutorials/1.4/graphics-sprite.php), it all make sense now :)
Hello,
You have to load the sf::Image in a sf::Texture (to make it simple, a sf::Texture is a picture living on the graphic card, but sf::Image is an array of pixels (image in RAM) ). Then, Create a sf::Sprite and set its texture to the newly created sf::Texture.
//It's an example, you have to keep the sf::Texture and sf::Sprite as members of your class
sf::Texture texture;
texture.loadFromImage(player->image);
sf::Sprite sprite;
sprite.setTexture(texture, true);
//Then, in PlayState::render()
game->window.draw(sprite);
EDIT : The tutorial you've read is for 1.6. In this version, sf::Texture doesn't exists, sf::Sprite used only sf::Image. Now on 2.0, you have to use sf::Texture.