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

Show Posts

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.


Messages - iSkull

Pages: [1]
1
General / Close Event from nothing
« on: March 20, 2011, 10:05:24 am »
I get it now, thanks

2
General / Close Event from nothing
« on: March 20, 2011, 09:38:01 am »
Hello,

I am encountering a problem with sf::Event::Closed

Let's say i have this code:

Code: [Select]
#include <SFML/Graphics.hpp>
int main()
{
    sf::RenderWindow App(sf::VideoMode(600,300,32), "Test");
    sf::Event Event;

    sf::Image img(10,10,sf::Color(0,0,0));
    sf::Sprite Spr;

    bool running=true;

    App.UseVerticalSync(true);

    img.SetSmooth(false);

    Spr.SetImage(img);
    Spr.SetScale(2,2);
    Spr.SetPosition(300,280);

    while(running)
    {
        App.GetEvent(Event);
       
        if(Event.Type==sf::Event::Closed)
                running=false;

        if(Event.Type==sf::Event::KeyPressed) {if(Event.Key.Code==sf::Key::Escape)running=false;}

        if(App.GetInput().IsKeyDown(sf::Key::Left))Spr.Move(-10,0);
        if(App.GetInput().IsKeyDown(sf::Key::Right))Spr.Move(10,0);
        if(Spr.GetPosition().x<-5) Spr.SetX(600); else if(Spr.GetPosition().x>605) Spr.SetX(0);

        App.Clear(sf::Color(0,150,0));
        App.Draw(Spr);
        App.Display();
    }
}


A simple program showing a moving square.

When I run it, 70% of times will instantly exit it.
In the console mode it returns 0, so i think there aren't errors or problem with the code.

I removed
Code: [Select]
if(Event.Type==sf::Event::Closed)
                running=false;


And it worked perfectly, so it seems that the program gets a Closed event from nothing.
Is there a way to fix this or an alternative to sf::Event::Closed?

3
Window / Input::IsKeyDown problem
« on: March 16, 2011, 06:59:41 pm »
Quote from: "James"
You can either check for keypresses directly through the events, or through the input handler instance.

If you just move those if(App.GetInput()...)s out of your event processing loop it should work fine.


It works perfectly now, thank you very much!

This topic can be closed.

4
Window / Input::IsKeyDown problem
« on: March 16, 2011, 06:24:45 pm »
Ok, here is the sourcecode of a program that reproduces the problem:

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(600,300,32), "Test");
    sf::Event Event;
    sf::Image img(10,10,sf::Color());
    sf::Sprite Spr;

    bool running=true;
    bool jumping=false;
    short jumpenergy=0;

    App.SetFramerateLimit(40);
    App.UseVerticalSync(true);
    img.SetSmooth(false);
    Spr.SetImage(img);
    Spr.SetCenter(5,5);
    Spr.SetScale(2,2);
    Spr.SetPosition(200,290);

    while(running)
    {
        while(App.GetEvent(Event))
        {
            if(Event.Type==sf::Event::Closed)
                running=false;

            if(Event.Type==sf::Event::KeyPressed){
                if(Event.Key.Code==sf::Key::Escape)running=false;
                if(Event.Key.Code==sf::Key::Up && !jumping){jumping=true;jumpenergy=15;}
            }
        if(App.GetInput().IsKeyDown(sf::Key::Left))Spr.Move(-10,0);
        if(App.GetInput().IsKeyDown(sf::Key::Right))Spr.Move(10,0);
        if(Spr.GetPosition().x<-5) Spr.SetX(600); else if(Spr.GetPosition().x>605) Spr.SetX(0);
        }
        if(jumping){if(jumpenergy>-16){Spr.SetY(Spr.GetPosition().y-jumpenergy);jumpenergy--;}
            else jumping=!jumping;}
        App.Clear(sf::Color(0,150,0));
        App.Draw(Spr);
        App.Display();
    }

}



PS:strangely, if i move the mouse over the application while is moving/jumping, it works just how i want to

5
Window / Input::IsKeyDown problem
« on: March 16, 2011, 05:32:01 pm »
Well, i don't really care which method i am using, just want it to process multiple keys.

Right now, if i hold the left arrow and press the up arrow to jump, the character will jump, but it will stop moving left, and i have to release and re-press the left arrow to make him move again.

I just want to fix this.

6
Window / Input::IsKeyDown problem
« on: March 16, 2011, 05:14:45 pm »
Hello,
I just started programming with SFML and i wanted to make a simple moving mechanism.

The first attempt was like:

Code: [Select]
if(App.GetInput().IsKeyDown(sf::Key::Left)){...}
if(App.GetInput().IsKeyDown(sf::Key::Right)){...}


But it couldn't process multiple inputs at once like jumping and moving.

I tried to use sf::Input::IsKeyDown() to try to fix that:
Code: [Select]
if(sf::Input::IsKeyDown(sf::Key::Left)){...}
if(sf::Input::IsKeyDown(sf::Key::Right)){...}

But i get this error:
Code: [Select]
error: cannot call member function 'bool sf::Input::IsKeyDown(sf::Key::Code) const'
Im using SFML 1.6 with MinGW and Code::Blocks
Sorry for my poor English.

Pages: [1]
anything