It's been awhile since I've needed help, but I can't for the life of me figure out why subtraction isn't doing what it should be I'm clearly missing something or some change to how C++ interprets subtraction, if you could point me in the right direction that would be awesome otherwise I'll just do a complete rewrite.
(Also ignore int sx, int sy I was using those to keep track of the position but using mOffset was simply easier)

#include "gfx.hxx"
#include "regfx.hxx"
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
    gfx g(false,1280,768,"Sprite Runner");
    bool quit = false;
    SDL_Event e;
    Sprite Menu("Menu.bmp",ren);
    ofstream file;"sp.log");

        while(SDL_PollEvent(&e) != 0)
          if(e.type == SDL_QUIT)
              quit = true;
          if(e.type == SDL_KEYDOWN && e.key.repeat == 0)
                case SDLK_w:
                    Menu.mOffset.y = Menu.mOffset.y - 1;

                case SDLK_s:
                    Menu.mOffset.y += 1;

                case SDLK_a:
                    Menu.mOffset.x = Menu.mOffset.x -1;

                case SDLK_d:
                    Menu.mOffset.x += 1;

          //Menu.mOffset.x =;
          //Menu.mOffset.y =;
          //file << "sx: " << << "\t" << "sy: " << << endl;
          //file << "mOffset.x: " << Menu.mOffset.x << "\t" << Menu.mOffset.y << endl;

    return 0;

//regfx aka sprite class

#ifndef _REGFX_HXX_
#define _REGFX_HXX_
#include <iostream>
#include <string>
#include <fstream>
#include <SDL.h>

class Sprite
    SDL_Texture * mSprite;
    int mWidth;
    int mHeight;

    SDL_Rect mOffset;
     int sx; //xloc
     int sy; //yloc
    Sprite(std::string imagePath, SDL_Renderer * rnd)
        SDL_Surface * spriteRes = SDL_LoadBMP(imagePath.c_str());
        mWidth = spriteRes->w;
        mHeight = spriteRes->h;
        mSprite = SDL_CreateTextureFromSurface(rnd,spriteRes);
        sx = 0;
        sy = 0;
        mOffset = {sx,sy,mWidth,mHeight};
    void setX(int x){sx = sx + x; mOffset.x = sx;}
    void setY(int y){sy = sy + y; mOffset.y = sy;}
    int getX(){return sx;}
    int getY(){return sy;}
    void render(SDL_Renderer * rnd)


#endif // _REGFX_HXX_

I believe that there may be some weird stuff going on in the background, going off of past experience x -= 1 is the same as x = (x-1), I've written far more complicated pieces of code but i'm having some trouble narrowing this issue down I've tried multiple approaches to get it to function as intended but no matter what i try either only down(s) and right(d) work or none do.

Oh man I feel dumb I was missing the break statement in my switch case so I never exited the while loop lmao doesn't explain why down and right worked though I'll mark it solved but if someone could explain what was actually happening I'd be quite interested to know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.