Boolean to indicate movement direction is never a good idea. We don't live in the 90's where bytes were rare, we're in 2020 and have access to enougth RAM for using millions of integer values. So you should rather make a general Move function and instead pass different offsets to it if you want to move right or left. Depending on the direction, you'll have a signed or unsigned value of for example -1 and 1 to move to the left or right on the X axis
game advice
I have only one sprite for idle. I need to know a direction to face a sprite when the player is staying in the idle position.
@Shaarigan well I have stubbed out some c++ console code to help me learn how to solve my directional problem using sprites,let me know if I am on the right track.
#include<iostream>
using namespace std;
float x = 0.0f, dir=0.0f;
void move_dir(float);
int main()
{
cout << "Enter direction l/r (-1,1): ";
cin >> dir;
cout << endl;
move_dir(dir);
system("pause");
return 0;
}
void move_dir(float direction)
{
if (direction == -1)
{
for (int i = 0; i < 5; i++)
{
x -= 0.5f;
cout << x << endl;
}
}
if (direction == 1)
{
for (int i = 0; i < 5; i++)
{
x += 0.5f;
cout << x << endl;
}
}
}
@8Observer8 I have almost solved my problem, I am able to get my sprite to move right but when I use the left key it jumps to the left side and then it moves right and backwards and when I press the right key it jumps to the right side of the screen. I hope this explanation is sufficient. here is the code I am working on.
void drawSprite()
{
glEnable(GL_TEXTURE_2D);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture[6]);
if (direction == 1)
{
glScalef(1.0f, 1.0f, 0.0f);
}
else if (direction == -1)
{
glScalef(-1.0f, 1.0f, 0.0f);
}
glTranslatef(0.0f, -70.0f, 0.0f);
glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
glBegin(GL_POLYGON);
glTexCoord3f(0.0f + screen, 0.0f, 0.0f);
glVertex3f(10.0f + move_up + y, -10.0f + move_sprite - x, 0.0f);
glTexCoord3f(0.125f + screen, 0.0f, 0.0f);
glVertex3f(10.0f + move_up + y, 10.0f + move_sprite - x, 0.0f);
glTexCoord3f(0.125f + screen, 1.0f, 0.0f);
glVertex3f(-10.0f + move_up + y, 10.0f + move_sprite - x, 0.0f);
glTexCoord3f(0.0f + screen, 1.0f, 0.0f);
glVertex3f(-10.0f + move_up + y, -10.0f + move_sprite - x, 0.0f);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
@pbivens67 please, google tutorials for beginners about modern OpenGL with shaders
Some of them:
@8Observer8 thanks for the links but I have decided to study up on my c++, I am reading the dietel and dietel text and doing the exercises in the backs of the chapters.