This site requires JavaScript, please enable it in your browser!
Greenfoot back
davemib123
davemib123 wrote ...

2014/7/18

getting focus to player object

davemib123 davemib123

2014/7/18

#
Hi, this seems to be bugging me. In the world class I would use:
public class Town extends World
{
    /**
     * Constructor for objects of class Town.
     * 
     */
    public Town()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        Greenfoot.start();
        addObject (new Hero(), 300, 200);
    }
}
For some reason I find that my Hero does not always respond straight away. I would need to Pause and then Run for the Hero to respond to keyboard commands. Any ideas on what is going on? The Hero has this in the Act method:
if (Greenfoot.isKeyDown("left"))
        {
            moveLeft();
        }
        if (Greenfoot.isKeyDown("right"))
        {
            moveRight();
        }
        if (Greenfoot.isKeyDown("up"))
        {
            moveUp();
        }
        if (Greenfoot.isKeyDown("down"))
        {
            moveDown();
        }
danpost danpost

2014/7/18

#
That may be a bug in greenfoot. Try inserting the following between lines 11 and 12 in your Town class code above:
WorldVisitor.startSequence(this);
davemib123 davemib123

2014/7/18

#
great. that seems to have done the trick.
You need to login to post a reply.