image goes away

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
emily
Posts: 22
Joined: November 9th, 2019, 9:04 pm
Location: Kentucky

image goes away

Post by emily » April 27th, 2020, 10:29 pm

How do I keep the different images of the PacMan from disappearing when I let up on the keys.
Beginner Tutorial 4.2 Code.zip
(3.59 MiB) Downloaded 157 times

User avatar
AleksiyCODE
Posts: 32
Joined: September 21st, 2019, 8:47 pm

Re: image goes away

Post by AleksiyCODE » April 28th, 2020, 7:17 am

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
I like ass

User avatar
emily
Posts: 22
Joined: November 9th, 2019, 9:04 pm
Location: Kentucky

Re: image goes away

Post by emily » April 29th, 2020, 12:56 am

ok thanks i'll try that method.

Post Reply