1
General / how to display alternate images at each timestep
« on: July 22, 2011, 11:00:47 pm »
:shock: :shock: :shock: OMG how could i miss that lol it now moves thank you
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.
s.setPosX(width/2);s.setPosY(height/10);
void SpaceInvadersDemo::init()
{
shipImage.LoadFromFile("myC++/images/asprite1.png");
shipImage2.LoadFromFile("myC++/images/asprite2.png");
shipSprite=sf::Sprite(shipImage), (shipImage2);
shipSprite.SetCenter(shipSprite.GetSize().x/2,shipSprite.GetSize().y/2);
s.setRadius(shipSprite.GetSize().x/2);
s.setPosX(width/2);s.setPosY(height/10);
}
void SpaceInvadersDemo::draw()
{
win.Clear(sf::Color(0,0,0));
shipSprite.SetPosition(s.getPosX(),s.getPosY());
win.Draw(shipSprite);
}
void SpaceInvadersDemo::getInput()
{
sf::Event Event;
while (win.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
win.Close();
//Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
win.Close();
}
}
void SpaceInvadersDemo::update()
{
sf::Clock Clock;
if (Clock.GetElapsedTime()>=Timestep)
{
shipSprite.SetImage(shipImage2);
s.setPosX(s.getPosX()+moveIncrement);
Clock.Reset();
}
void SpaceInvadersDemo::play()
{
//the game loop
draw();//the offscreen buffer
getInput();//from the user
update();//integrate user input and any game movement which is automatic
}
if (Clock.GetElapsedTime()>=Timestep)
{
shipSprite.SetImage(shipImage2);
s.setPosX(s.getPosX()+moveIncrement);
Clock.Reset();
}
if (Clock.GetElapsedTime()==Timestep)
{
shipSprite=sf::Sprite(shipImage2);
s.setPosX(s.getPosX()+moveIncrement);
}