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

Author Topic: How to listen iOS/Android touch event for window.pollEvent(event)  (Read 1744 times)

0 Members and 1 Guest are viewing this topic.

smartly

  • Newbie
  • *
  • Posts: 10
    • View Profile
How to listen shape's touch event?

#import <SFML/Main.hpp>
#import <SFML/Graphics.hpp>

void main()
{
    sf::RenderWindow window(sf::VideoMode(640, 1136), "Putao Application");
   
    sf::CircleShape shape;
    shape.setPosition(100, 100);
    shape.setRadius(100.0f);
    shape.setFillColor(sf::Color::Cyan);
   
    while (window.isOpen())
    {
        sf::Event event;
       
        while(window.pollEvent(event))
        {
            // here example code?
        }

        window.clear();
        window.draw(shape);
        window.display();
    }
}
« Last Edit: October 28, 2014, 07:36:18 pm by smartly »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: How to listen iOS/Android touch event for window.pollEvent(event)
« Reply #1 on: October 28, 2014, 07:55:06 pm »
Events are provided by the OS for windows, not arbitrary regions of the screen.

When you receive a touch event for your window, you have to check whether it happened inside the shape or not.  Functions like sf::Rect<T>::contains() should make this very simple.

 

anything