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

Author Topic: Gods help!  (Read 1944 times)

0 Members and 1 Guest are viewing this topic.

mjaoo

  • Newbie
  • *
  • Posts: 9
    • View Profile
Gods help!
« on: July 19, 2009, 10:17:08 pm »
Hi. Im used to SFML 1.2 and updated my verision to 1.5 today and i dunno if this is one major bugg or just my code.

This is a labbingcode for a project im doing in school so dont lol at the code.


Code: [Select]
 while (App.IsOpened())
    {
        // Handle events
        Event Event;
        while (App.GetEvent(Event))
        {
            // Window closed or escape key pressed : exit
            if ((Event.Type == Event::Closed) ||
               ((Event.Type == Event::KeyPressed) && (Event.Key.Code == Key::Escape)))
            {
                App.Close();
                break;
            }
        }
        if (App.GetInput().IsKeyDown(Key::Left))
        {
            hero.move_x(-1);
            my_room.move_x(2);
        }
        if (App.GetInput().IsKeyDown(Key::Right))
        {
            hero.move_x(1);
            my_room.move_x(-2);

            if(hero.avatar->x == 300)
            {
                for(int i=hero.avatar->x;i!=0;i--)
                {
                    hero.move_x(-1);
                    my_room.move_x(-2);
                    //Sleep(0.1);
                }
            }
        }

        my_room.display(&App);
        hero.display(&App);
        App.Display();
        //i++;
    }

    return EXIT_SUCCESS;
    return 0;
}


void room::display(RenderWindow * App)
{
    App->Draw(wallpaper->my_picture);
}

void room::move_x(int value)
{
    wallpaper->x += value;
    wallpaper->my_picture.SetX(wallpaper->x);
}



void character::display(RenderWindow * App)
{
    App->Draw(avatar->my_picture);
}

void character::move_x(int value)
{
    avatar->x += value;
    avatar->my_picture.SetX(avatar->x);
}



Simpley i have two pictures one in the background and one character over it. When heros x reaches 300 it will loop down(like in megaman)
But after the loop had done his work ive now got two heroes on the screen. Is this something common? + the pictures is moving and stuff when the second hero appears.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Gods help!
« Reply #1 on: July 19, 2009, 10:57:34 pm »
You must now call App.Clear() to clear the screen before rendering each frame.
Laurent Gomila - SFML developer

mjaoo

  • Newbie
  • *
  • Posts: 9
    • View Profile
Gods help!
« Reply #2 on: July 19, 2009, 11:18:07 pm »
Ty alot! :o <3