Sign in to follow this  
Noxir

help plizz???

Recommended Posts

Noxir    100
Hey ya why isn't this code working, when I press the left arrow the image changes to the left walking one, but when I press the right arrow nothing happens, why
      	    if (keys[VK_LEFT])
            {
                texture[0] = texture14[0];
                p1x -= 0.1f;
                if(p1x > 14.0f && p1x < 16.0f && p1y >= 0.0f)
                {
                    if(passable == false)
                    {
                    p1x += 0.1f;
                    }    
                }    
            }

            if (keys[VK_RIGHT])
            {   
                texture14[0] = texture[0];
                p1x += 0.1f;
                if(p1x > 14.0f && p1x < 16.0f && p1y >= 0.0f)
                {
                    if(passable == false)
                    {
                     p1x -= 0.1f;
                    }    
                }
            }

Thnxz [Edited by - Noxir on June 10, 2005 7:08:15 AM]

Share this post


Link to post
Share on other sites
SirRichard42    132
When you run the left-key code, you have this statement:
texture[0] = texture14[0];

That sets the value of texture[0] to be equal to the value of texture14[0].. So then, when you run the right-key code later, it does this:
texture14[0] = texture[0];

At this point the two variables already hold the same value (the original value of texture14[0] was lost when you pressed the left key) so the texture won't change. You need to find a different way to do what you want to do.

Another helpful hint - you will find that the most experienced, highest quality programmers don't like to just throw stuff together to make it work. They care very much about the appearance of the code - like art. Considering this, it would be a good habit to learn to use identations to visually group your C++ blocks together. It increases readability by a great deal and it will help you when debugging.

Richard

Share this post


Link to post
Share on other sites
Noxir    100
Thanks :D dunno how to fix it though, I'll just use 1 image for the player instead ;)

[Edited by - Noxir on June 10, 2005 7:30:19 AM]

Share this post


Link to post
Share on other sites
dawidjoubert    161
What he means is do this instead
#define TEXTURE_LEFT 0
#define TEXTURE_RIGHT 1
if (keys[VK_LEFT])
{
// New Code
CurrentTexture = TEXTURE_LEFT;
p1x -= 0.1f;
if(p1x > 14.0f && p1x < 16.0f && p1y >= 0.0f)
{
if(passable == false)
{
p1x += 0.1f;
}
}
}

if (keys[VK_RIGHT])
{
// New Code
CurrentTexture = TEXTURE_RIGHT;
p1x += 0.1f;
if(p1x > 14.0f && p1x < 16.0f && p1y >= 0.0f)
{
if(passable == false)
{
p1x -= 0.1f;
}
}
}

// Render Code
DrawScene ()
{
glclear(...
glenable...
glloadidentity..
...
glBindTexture(GL_TEXTURE_2D,texture[CurrentTexture])
}
// Load Code
LoadTextures()
{
loadtga("filename_texture_right.tga",texture[TEXTURE_RIGHT])
loadtga("filename_texture_left.tga",texture[TEXTURE_LEFT])
}

Share this post


Link to post
Share on other sites

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