sir Laurent, Im using the sf::Texture because when i use sf::Image
and error occurs when i try to pass it in sf::Sprite
Here is my code:
#include "SFML/Graphics.hpp"
int main()
{
sf::RenderWindow Window(sf::VideoMode(640,480,32),"Graphics!");
sf::Image image;
image.LoadFromFile("untitled.png");
sf::Sprite Sprite;
if (!image.LoadFromFile("untitled.png"))
return 1;
Sprite.SetTexture(image);
Sprite.SetSubRect(sf::IntRect(0,0,55,66));
while (Window.IsOpened())
{
sf::Event Event;
while (Window.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
Window.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::LAlt))
{
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::F4))
Window.Close();
}
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Down))
Sprite.SetSubRect(sf::IntRect(70,8,65,65));
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Left))
Sprite.SetSubRect(sf::IntRect(8,8,65,65));
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Right))
Sprite.SetSubRect(sf::IntRect(135,8,65,65));
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Up))
Sprite.SetSubRect(sf::IntRect(195,8,65,65));
}
Window.Clear();
Window.Draw(Sprite);
Window.Display();
}
return 0;
}
And this is the error.
C:\Documents and Settings\JONG\My Documents\CodeBlocks\SFML TEST\main.cpp||In function 'int main()':|
C:\Documents and Settings\JONG\My Documents\CodeBlocks\SFML TEST\main.cpp|12|error: no matching function for call to 'sf::Sprite::SetTexture(sf::Image&)'|
C:\sfml\sfml2\include\SFML\Graphics\Sprite.hpp|83|note: candidates are: void sf::Sprite::SetTexture(const sf::Texture&, bool)|