sfml中怪异的软件更新错误

时间:2019-04-27 18:08:16

标签: c++ sfml

我用c ++在sfml中制作了一个简单的动画类,但是它没有用,在调试过程中,我添加了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));

在主文件中,我在名为looperLeftAnimation的主循环简单setAnimation类之前,而在主循环中,我拥有

Player.update(&playerLeftAnimation,deltaTime);

我知道它的很多代码,并且可能令人困惑,但是我真的卡在了这个错误上,我不知道如何解决它

0 个答案:

没有答案