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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - PlatformDeveloper

Pages: [1]
1
General / Y Position rapidly going up. Invalid texture size.
« on: June 29, 2017, 08:17:11 pm »
Hello guys, I need a little help with my code. I cant give you guys a working example because my code is spread out between around 500 files. But here is one of my classes I need help with.

class AnimatedTile
{
protected:
        std::vector<sf::RectangleShape> Frames = std::vector<sf::RectangleShape> (10);
        sf::Texture texs[11];
        int FrameNum = 0;
        int upZero = 0;
public:
        AnimatedTile()
        {

        }

        AnimatedTile(float s1, float s2, float x1, float y1, sf::String Spritesheet)
        {
                sf::Image img;
                if (!img.loadFromFile(Spritesheet))
                        return;
                sf::Texture texsA[11];
                for (int i = 0; i < 11; i++)
                {
                        texs[i] = texsA[i];
                        sf::RectangleShape pb;
                        if (!texs[i].loadFromImage(img, sf::IntRect(64 * i, 94 * i, 64, 94)))
                                return;
                        pb.setTexture(&texs[i]);
                        pb.setSize(sf::Vector2f(s1, s2));
                        pb.setPosition(x1, y1);
                        Frames.push_back(pb);
               
                }
        }

        sf::Vector2f getPosition()
        {
                return Frames.at(FrameNum).getPosition();
        }

        void setPosition(float x, float y)
        {
                for (int i = 0; i < 11; i++)
                        Frames[i].setPosition(x, y);
                return;
        }

        sf::Rect<float> getGlobalBounds()
        {
                return Frames[FrameNum].getGlobalBounds();
        }

        sf::Vector2f getOrigin()
        {
                return Frames[FrameNum].getOrigin();
        }

        void nextFrame()
        {
                if (FrameNum == 10 && upZero == 0) {
                        FrameNum--;
                        upZero = 1;
                }
                else if (FrameNum == 0 && upZero == 1) {
                        FrameNum++;
                        upZero = 0;
                }
                else if (upZero == 0)
                        FrameNum++;
                else if (upZero == 1)
                        FrameNum--;
        }

        virtual void draw(sf::RenderTarget& target, sf::RenderStates states = *new sf::RenderStates()) const
        {
                target.draw(Frames[FrameNum]);
        }
};

There is an invalid texture size error, and the Y position of my player is rapidly going up.
The program compiles correctly so I do not know where the error is.

Here is my spritesheet,
https://www.dropbox.com/s/9nn3u14hv8a0fx7/p1_walk.png?dl=0

Thanks,
PlatformerDeveloper.

Pages: [1]
anything