странная ошибка обновления программного обеспечения в sfml - PullRequest
0 голосов
/ 27 апреля 2019

Я сделал простой класс анимации в sfml с c ++, и он не работал, во время отладки я добавил строку std :: cout, и неожиданно она начала работать отлично, попытался удалить ее, и ошибка снова вернулась, не имеет значения, является ли строка std :: cout или printf, и не имеет значения, что я печатаю, я думаю, что это ошибка sfml, хотя я не уверен, что мне интересно, есть ли способ ее передать / исправить. Есть ли очевидное решение, которое я пропустил? ошибка в том, что анимация застревает на второй анимации (из 3)

заголовок класса анимации:

#pragma once
#include <SFML\Graphics.hpp>
#include <iostream>
class SetAnimation
{
public:
    SetAnimation(unsigned int row, unsigned int totalImages, bool Loop) { this->row = row, this->totalImages = totalImages; this->Loop = Loop; };
    ~SetAnimation() {};


public:
    unsigned int row;
    unsigned int totalImages;
    bool Loop;

};


class Animation
{
public:
    Animation(sf::Texture* texture, sf::Vector2u totalImages, unsigned int delay);
    ~Animation();
    sf::IntRect update(SetAnimation* currentAnimation, float deltaTime);

private:
    sf::IntRect textureRect;
    unsigned int delay;
    float totalTime;
    unsigned int currentImage = 0;
    bool LeftToRight = true;
};

файл анимации cpp

#include "Animations.h"



Animation::Animation(sf::Texture* texture, sf::Vector2u totalImages, unsigned int delay)
{
    this->textureRect.width = texture->getSize().x / totalImages.x;
    this->textureRect.height = texture->getSize().y / totalImages.y;
    this->delay = delay;
    this->totalTime = delay;
}

Animation::~Animation()
{
}

sf::IntRect Animation::update(SetAnimation* currentAnimation, float deltaTime)
{
    this->textureRect.top = currentAnimation->row * this->textureRect.height;
    totalTime += deltaTime;

    printf("working \n");
    if (totalTime >= delay) 
    {
        this->textureRect.left = currentImage * textureRect.width;

        if (currentAnimation->Loop) 
        {
            if (LeftToRight) 
            {
                currentImage++;
                if (currentImage >= currentAnimation->totalImages) 
                {
                    LeftToRight = false;
                    currentImage--;
                }
            }

            if (!LeftToRight)
            {
                currentImage--;
                if (currentImage == 0)
                {
                    LeftToRight = true;
                }
            }


        }
        else 
        {
            if (currentImage >= currentAnimation->totalImages) { currentImage = 0; }
        };

        totalTime = 0;
    }

    return textureRect;
}

В классе заголовка плеера у меня есть:

Animation* PlayerAnimation;

В конструкторе плеера у меня есть:

PlayerAnimation = new Animation(texture, sf::Vector2u(3,2), 100);

В функции обновления плеера у меня есть:

setTextureRect(PlayerAnimation->update(currentAnimation, deltaTime));

В основном файле, который у меня есть, перед основным простым классом setAnimation, называемым playerLeftAnimation, и в основном цикле, у меня есть

Player.update(&playerLeftAnimation,deltaTime);

Я знаю, что в нем много кода, и это может сбивать с толку, но я действительно застрял на этой ошибке, и я понятия не имею, как ее исправить

...