Sign in to follow this  

Problem with my sprite class

This topic is 4289 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. Just finnished my sprite class. But now I have a problem, when I draw a big non animated frame big(1280x1024) the fps drops to ~11. The problem isn't that the image is to big, because I had a simple non-animateds sprite class before this one. And then it all worked marvelous. ~50 fps all the time. So I come here to ask for help spotting the error in my code that slows down rendering so much. I have looked over and over, but can't find anything. Well insecure on how much code I should post, I have three classes (cFrame, cAnimation and cSprite) so it's pretty much code. Don't know if it will intimitate people from helping me =) My guess is that the problem lies in the draw function, but I cant find anything. I'll post the draw functions here now, and if someone wants to help me I'll post the whole code.
[source lang=cpp]
void cSprite::draw(SDL_Surface *dest)
{
    if(visible)
    {
        if(animations.at(currAnim).getFrames() > 1)
        {
            if(paused == false)
            {
                if(animations.at(currAnim).getFrameTime() + animations.at(currAnim).getCurrFrameDelay() <= SDL_GetTicks() )
                {
                    animations.at(currAnim).nextFrame();
                    animations.at(currAnim).setFrameTime( SDL_GetTicks() );
                }
            }
        }

        SDL_BlitSurface(pImgManager->get(animations.at(currAnim).getCurrFrameImg()), NULL, dest, &rect);
    }
}

void cSprite::draw(SDL_Surface *dest, int x, int y)
{
    if(visible)
    {
        if(animations.at(currAnim).getFrames() > 1)
        {
            if(paused == false)
            {
                if(animations.at(currAnim).getFrameTime() + animations.at(currAnim).getCurrFrameDelay() <= SDL_GetTicks() )
                {
                    animations.at(currAnim).nextFrame();
                    animations.at(currAnim).setFrameTime( SDL_GetTicks() );
                }
            }
        }

        rect.x = x;
        rect.y = y;

        SDL_BlitSurface(pImgManager->get(animations.at(currAnim).getCurrFrameImg()), NULL, dest, &rect);
    }

}

void cSprite::drawOnce(SDL_Surface *dest)
{
    if(visible)
    {
        if(animations.at(currAnim).getFrames() > 1)
        {
            if(paused == false)
            {
                if(animations.at(currAnim).getFrameTime() + animations.at(currAnim).getCurrFrameDelay() <= SDL_GetTicks() )
                {
                    animations.at(currAnim).nextFrame();
                    animations.at(currAnim).setFrameTime( SDL_GetTicks() );
                    if(animations.at(currAnim).lastFrame()) { visible = false; }
                }
            }
        }

        SDL_BlitSurface(pImgManager->get(animations.at(currAnim).getCurrFrameImg()), NULL, dest, &rect);
    }
}

void cSprite::drawOnce(SDL_Surface *dest, int x, int y)
{
    if(visible)
    {
        if(animations.at(currAnim).getFrames() > 1)
        {
            if(paused == false)
            {
                if(animations.at(currAnim).getFrameTime() + animations.at(currAnim).getCurrFrameDelay() <= SDL_GetTicks() )
                {
                    animations.at(currAnim).nextFrame();
                    animations.at(currAnim).setFrameTime( SDL_GetTicks() );
                    if(animations.at(currAnim).lastFrame()) { visible = false; }
                }
            }
        }

        rect.x = x;
        rect.y = y;

        SDL_BlitSurface(pImgManager->get(animations.at(currAnim).getCurrFrameImg()), NULL, dest, &rect);
    }
}



Greatful for any help. And also comments on the draw_once function, not shure thats a good way to do it. Thanks. [Edited by - walle on March 15, 2006 2:49:29 AM]

Share this post


Link to post
Share on other sites

This topic is 4289 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this