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 - rubikshift

Pages: [1]
1
General / Re: Issue with Joystick axes
« on: June 16, 2013, 12:42:05 pm »
I tried to rework the code, but I' don't know what i'm doing wrong. I don't understand everything what i should do. I don't know what else i should do.
[EDIT] Ok, it works, i maybe i did something wrong in actual version, but it works.
#include <SFML\Graphics.hpp>
#include <SFML\System\Clock.hpp>
#include <iostream>

int main()
{
        sf::Clock clock;
        sf::ContextSettings settings;
       

        sf::CircleShape ksztalt (50);
        ksztalt.setPosition(400,300);
        ksztalt.setFillColor(sf::Color::Green);
        ksztalt.setOutlineColor(sf::Color::Black);
        ksztalt.setOutlineThickness(8);

        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window", sf::Style::Default, settings);
       
        settings.antialiasingLevel = 16;

        if(sf::Joystick::isConnected(0))
                std::cout << "Joystick is connected :)" << std::endl;
        else
                std::cout <<"Joystick is not connected :(" << std::endl;

        int buttoncount = sf::Joystick::ButtonCount;
                std::cout << buttoncount << std::endl;
        sf::Vector2f wektor(sf::Joystick::getAxisPosition(0, sf::Joystick::X), sf::Joystick::getAxisPosition(0, sf::Joystick::Y));

        while (window.isOpen())
        {
float cos1 = wektro.x;
float cos2 = wektor.y;
                window.clear(sf::Color::White);
                window.draw(ksztalt);
                window.display();
       
                sf::Event event;

        while (window.pollEvent(event))
        {      
                        if (event.type == sf::Event::Closed)
                window.close();
                }      
                wektor.x = sf::Joystick::getAxisPosition(0, sf::Joystick::X);
                wektor.y = sf::Joystick::getAxisPosition(0, sf::Joystick::Y);
                if((wektor.x != cos1) || (wektor.y != cos2) || ((wektor.x != cos1) && (wektor.y != cos2)))
                        ksztalt.move(wektor.x/10, wektor.y/10);
                std::cout << wektor.x << "\t\t" << wektor.y << std::endl;
                if(sf::Joystick::isButtonPressed(0, 1))
                        ksztalt.setFillColor(sf::Color::Green);
                               
                if(sf::Joystick::isButtonPressed(0, 2))
                        ksztalt.setFillColor(sf::Color::Red);
                       
                if(sf::Joystick::isButtonPressed(0, 3))
                        ksztalt.setFillColor(sf::Color::Yellow);

                if(sf::Joystick::isButtonPressed(0, 0))
                        ksztalt.setFillColor(sf::Color::Blue);

        }
        return EXIT_SUCCESS;
}

 
NOTE: cos1 and cos2 aren't cosinous, cos (correct coś) in polish means something, i use this word because i haven't idea.

2
General / Re: Issue with Joystick axes
« on: June 14, 2013, 09:46:36 pm »
Thanks Laurent,
I'm just learning SFML (also c++, but longer). I like when someone give me advice (most when it is about elementary things  :) ). I'll try tomorrow rework my program.

3
General / Re: Issue with Joystick axes
« on: June 14, 2013, 06:54:24 pm »
#include <SFML\Graphics.hpp>
#include <SFML\System\Clock.hpp>
#include <iostream>

int main()
{
        sf::Clock clock;
        sf::ContextSettings settings;
        sf::Vector2f wektor(sf::Joystick::getAxisPosition(0, sf::Joystick::X), sf::Joystick::getAxisPosition(0, sf::Joystick::Y));

        sf::CircleShape ksztalt (50);
        ksztalt.setPosition(400,300);
        ksztalt.setFillColor(sf::Color::Green);
        ksztalt.setOutlineColor(sf::Color::Black);
        ksztalt.setOutlineThickness(8);

        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window", sf::Style::Default, settings);
       
        settings.antialiasingLevel = 16;

        if(sf::Joystick::isConnected(0))
                std::cout << "Joystick is connected :)" << std::endl;
        else
                std::cout <<"Joystick is not connected :(" << std::endl;

        int buttoncount = sf::Joystick::ButtonCount;
                std::cout << buttoncount << std::endl;

        while (window.isOpen())
        {

                wektor.x = sf::Joystick::getAxisPosition(0, sf::Joystick::X);
                wektor.y = sf::Joystick::getAxisPosition(0, sf::Joystick::Y);
               
                sf::Joystick::update();

                window.clear(sf::Color::White);
                window.draw(ksztalt);
                window.display();
       
                sf::Event event;

        while (window.pollEvent(event))
        {      
                        if (event.type == sf::Event::Closed)
                window.close();
                       
                        else   
                       
                                if(sf::Joystick::isButtonPressed(0, 1))
                                        ksztalt.setFillColor(sf::Color::Green);
                               
                                if(sf::Joystick::isButtonPressed(0, 2))
                                        ksztalt.setFillColor(sf::Color::Red);
                       
                                if(sf::Joystick::isButtonPressed(0, 3))
                                        ksztalt.setFillColor(sf::Color::Yellow);

                                if(sf::Joystick::isButtonPressed(0, 0))
                                        ksztalt.setFillColor(sf::Color::Blue);

                                ksztalt.move(wektor.x*clock.getElapsedTime().asSeconds()/15, wektor.y*clock.getElapsedTime().asSeconds()/15);

                }
        }
        return EXIT_SUCCESS;
}

Ok, here is a code.

4
General / Issue with Joystick axes
« on: June 13, 2013, 07:54:02 pm »
Hi,
On the beginning i'd like to say, i'm learning English for few years, and i could make mistakes (wrong write something and etc.).
Few days ago i started learning sfml 2.0 on Visual Studio 2012. I created a simple program, which draw a shape and user can move it using joystick. I have a issue with axes, in source code i use only axis X and Y, but when i start my program and tried it i saw that when i do anything with joystick a shape moves. When i pressed A, B, X, Y or use right analog stick. I want that the shape moves only when i use left analog stick.
Please help.

Pages: [1]
anything