Hello,
i have a Spritesheet (the animation is in 24 Frames), now it only plays when my finger is on the touch Button (RectangleShape button). But i need to change this, i want that the SpriteSheet animation still plays automaticly one time when i touched the Button, without hold the finger on and without repeating the animation, how can i fix it? Here is the part if the code:
...
//init Sprite( its a SpriteSheet)
sf::Texture texture;
texture.loadFromFile("test1.png");
sf::Sprite sprite;
sprite.setPosition(300, 500);
sprite.setScale(5, 5);
sprite.setTexture(texture);
//init Button
sf::RectangleShape button;
button.setSize(sf::Vector2f(600, 200));
button.setPosition( sf::Vector2f(500, 1900));
button.setFillColor(sf::Color::Red);
sf::Clock clock;
sf::Vector2f animRect;
while (window.isOpen())
{
sf::Event event;
//Set Touch Coordinates to Screen
sf::Vector2i pixelPos = sf::Touch::getPosition(0, window);
sf::Vector2f worldPos = window.mapPixelToCoords(pixelPos);
//Set the Rect for the part of the SpriteSheet
sprite.setTextureRect(sf::IntRect (animRect.x * 101, animRect.y * 232, 101, 232));
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//FloatRect fot the button Sprite
sf::FloatRect btnRect = button.getGlobalBounds();
//if touch the Button
if(btnRect.contains(worldPos)){
if(clock.getElapsedTime().asSeconds() >= 0.2){
animRect.x++;
if(animRect.x * 101 >= texture.getSize().x)
animRect.x = 0;
animRect.y = 0;
clock.restart();
}
}