SDL2 images appear warped on edges of window when using BlitScaled()

Viewed 28

The title says it all. Images are warped on the edge of my window when I use SDL_Blit_Scaled(). here is a picture of the issue Warped sprite on top of screen

those black lines are not supposed to be there. It seems to be reading part of the next sprite in my sprite atlas:

Sprite atlas idk why this is happening. when I render a sprite to the screen I run this function in my custom class:

const int GameObject::draw(SDL_Surface windowSurface, Camera& camera)
{
    if (edge(1) - camera.posX + (camera.windowWidth / 2) < camera.windowWidth && edge(3) - camera.posX + (camera.windowWidth / 2) > 0 && -edge(4) + camera.posY + (camera.windowHeight / 2) < camera.windowHeight && -edge(2) + camera.posY + (camera.windowHeight / 2) > 0)
    {
        SDL_Rect rect = { (id - 1) * imgWidth, (type - 1) * imgHeight, imgWidth, imgHeight };
        //SDL_Rect dstrect = spritePos(posX - camera.posX + (camera.windowWidth / 2), -posY + camera.posY + (camera.windowHeight / 2));
        SDL_Rect dstrect = { edge(1) - camera.posX + (camera.windowWidth / 2), -edge(4) + camera.posY + (camera.windowHeight / 2), scaleX * imgWidth, scaleY * imgHeight };
        SDL_BlitScaled(&imageSurface, &rect, &windowSurface, &dstrect);
    }
    return 1;
}

GameObject.h:

class GameObject
{
public:
    const int draw(SDL_Surface windowSurface, Camera& camera);

    int edge(int dir)
    {
        if (dir == 1)
            return posX - (imgWidth * scaleX) / 2;
        if (dir == 2)
            return posY - (imgWidth * scaleX) / 2;
        if (dir == 3)
            return posX + (imgWidth * scaleX) / 2;
        if (dir == 4)
            return posY + (imgHeight * scaleY) / 2;
    }

    int id = 6;
    int type = 2;
    int imgWidth = 10;
    int imgHeight = 10;
    int scaleX = 10;
    int scaleY = 10;
    int posX = 0;
    int posY = 0;

    SDL_Surface imageSurface;

    //other stuff that's not relevant in this context
};

yes ik that the "edge" function is in the .h file instead of the .cpp but im too lazy to deal with it rn. any help is appreciated!

0 Answers
Related