Hi there,
I'm teaching coding and we're doing some very basic movement. I have made a project and it simply has a "hero" class and it can be moved by pressing keys (left, right, up or down). I've probably taught this 10 times over the past 5 years using Greenfoot without issue, but this time the program runs okay for awhile and then the hero just stops responding to the key presses, or does so sporadically.
Initially I thought it might be an issue with my computer, but my students are able to replicate on their devices. I'm not sure what is wrong? Any thoughts?
Here is the only code that is in the hero act() method:
I would love to get this solved as my students are getting frustrated with activity one!!!
Thanks very much.
public void act()
{
xPos = getX();
yPos = getY();
if (Greenfoot.isKeyDown("a"))
{
setLocation(xPos-5, yPos);
}
else if (Greenfoot.isKeyDown("d"))
{
setLocation(xPos+5, yPos);
}
else if (Greenfoot.isKeyDown("w"))
{
setLocation(xPos, yPos-5);
}
else if (Greenfoot.isKeyDown("s"))
{
setLocation(xPos, yPos+5);
}
}
