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

Author Topic: change IntRect in Sprites image  (Read 1523 times)

0 Members and 1 Guest are viewing this topic.

demonking

  • Newbie
  • *
  • Posts: 2
    • View Profile
change IntRect in Sprites image
« on: January 09, 2011, 01:50:57 pm »
Hello guys,

i have a problem with my Spritesheet, so i want some kind of hints or something else. :)

I have use the SuFu but doesn't found anything that helps.

here is my code :

Code: [Select]

#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;
}




I have tried to Load the image new, reset the IntRect, the result was, that i get a sprite on my screen, but he doesn't move.
The only thing that helps was to push_back all Sprites in a vector and go through this.
Is there some other way?
Some hints would be enough =)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
change IntRect in Sprites image
« Reply #1 on: January 09, 2011, 01:53:23 pm »
You must have an event loop (GetEvent) so that events are processed and App.GetInput() can return correct stuff.
Laurent Gomila - SFML developer

demonking

  • Newbie
  • *
  • Posts: 2
    • View Profile
change IntRect in Sprites image
« Reply #2 on: January 09, 2011, 01:58:22 pm »
i feel ashmed  :oops:
such mistake .
thx a lot Laurent :D

 

anything