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