image goes away
image goes away
How do I keep the different images of the PacMan from disappearing when I let up on the keys.
- AleksiyCODE
- Posts: 32
- Joined: September 21st, 2019, 8:47 pm
Re: image goes away
All of your PutPixel calls are in 'if' statements. So when you don't press any keys, all of if statements are skipped and no pixels are drawn. In this case it is better to separate moving logic from drawing logic. I think a good solution would be adding a variable, that would indicate what direction PacMan is facing and updating this variable based on if statements.
if (wnd.kbd.KeyIsPressed(VK_RIGHT))
{
x = x + 3;
faceDir = 0;//update facing direction here
}
if (wnd.kbd.KeyIsPressed(VK_LEFT))
{
x = x - 3;
faceDir = 1;//update facing direction here
}
if (wnd.kbd.KeyIsPressed(VK_DOWN))
{
y = y + 3;
faceDir = 2;//update facing direction here
}
if (wnd.kbd.KeyIsPressed(VK_UP))
{
y = y - 3;
faceDir = 3;//update facing direction here
}
and after that put your drawing code in similar if statements
if(faceDir==0)
{
//draw right facing
}
if(faceDir==1)
{
//draw left facing
}
..etc
if (wnd.kbd.KeyIsPressed(VK_RIGHT))
{
x = x + 3;
faceDir = 0;//update facing direction here
}
if (wnd.kbd.KeyIsPressed(VK_LEFT))
{
x = x - 3;
faceDir = 1;//update facing direction here
}
if (wnd.kbd.KeyIsPressed(VK_DOWN))
{
y = y + 3;
faceDir = 2;//update facing direction here
}
if (wnd.kbd.KeyIsPressed(VK_UP))
{
y = y - 3;
faceDir = 3;//update facing direction here
}
and after that put your drawing code in similar if statements
if(faceDir==0)
{
//draw right facing
}
if(faceDir==1)
{
//draw left facing
}
..etc
I like ass
Re: image goes away
ok thanks i'll try that method.