Jump to content
  • Advertisement
Sign in to follow this  
Noxir

help plizz???

This topic is 4734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!