Not an emergency because the code still works, I'm mainly just curious.
I'm using raylib to make an RPG. I wrote a function that changes the displayed rotational sprite depending on the last direction the player moved. If you're unfamiliar with raylib, textures are a variable type which must be initialized with the function LoadTexture(const char *fileName)
. This is taken care of at program start by another function I wrote. For some reason, g++ is warning me that these variables are unused, even though they clearly are, due to the fact that the sprite is being rendered.
This is my declaration, in draw.h:
// Sprite variables
static Texture pUp; // Player facing up
static Texture pDown; // Player facing down
static Texture pLeft; // Player facing left
static Texture pRight; // Player facing right
I use a function PSetSprite(Dir pDir)
which takes the current direction of the player as an argument and returns the correct rotational sprite.
Texture PSetSprite(Dir pDir) {
static Texture pSprite = pDown;
switch (pDir) {
case UP:
pSprite = pUp;
break;
case DOWN:
pSprite = pDown;
break;
case LEFT:
pSprite = pLeft;
break;
case RIGHT:
pSprite = pRight;
break;
case UP_LEFT:
pSprite = pLeft;
break;
case UP_RIGHT:
pSprite = pRight;
break;
case DOWN_LEFT:
pSprite = pLeft;
break;
case DOWN_RIGHT:
pSprite = pRight;
break;
default:
break;
}
return pSprite;
}
This is then passed to the player object with player.Draw(const Texture pSprite)
and drawn to the screen. Deleting the variables obviously breaks my program, so what gives?
For those who asked, I am using version 12.2.0 of g++, and the specific error is "'pUp' defined but not used," x4 for each rotational sprite.