1
Graphics / change IntRect in Sprites image
« on: January 09, 2011, 01:58:22 pm »
i feel ashmed :oops:
such mistake .
thx a lot Laurent
such mistake .
thx a lot Laurent
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <vector>
int main(){
sf::Sprite sprite_;
sf::Image image_;
sf::RenderWindow App(sf::VideoMode(800,600,32),"RUN FOREST RUN !!! ");
if(!image_.LoadFromFile("char.png"))
return EXIT_FAILURE;
sprite_.SetImage(image_);
sprite_.SetPosition(200.f,200.f);
sprite_.SetSubRect(sf::IntRect(0,0,25,35));
while(App.IsOpened())
{
float ElapsedTime = App.GetFrameTime();
if(App.GetInput().IsKeyDown(sf::Key::Up))
{
sprite_.SetSubRect(sf::IntRect(0,25,25,50));
sprite_.Move(50.f,50.f);
}
if(App.GetInput().IsKeyDown(sf::Key::Down)){
sprite_.SetSubRect(sf::IntRect(0,105,25,140));
sprite_.Move(100.f,100.f);
}
if(App.GetInput().IsKeyDown(sf::Key::Left)){
sprite_.SetSubRect(sf::IntRect(0,70,25,105));
sprite_.Move(150.f,150.f);
}
if(App.GetInput().IsKeyDown(sf::Key::Right)){
sprite_.SetSubRect(sf::IntRect(0,140,25,175));
sprite_.Move(200.f,200.f);
}
App.Clear();
App.Draw(sprite_);
App.Display();
}
return EXIT_SUCCESS;
}