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

2014/2/9

atWorldEdge won't work; cannot find symbol - method atWorldEdge()

duckduckduck duckduckduck

2014/2/9

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Snake here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Snake extends Actor
{
    /**
     * Act - do whatever the Snake wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(5);
        if (atWorldEdge())
        {
            turn(180);
        }
    }    
}
danpost danpost

2014/2/9

#
'atWorldEdge' is not a method in the Actor class API. It is, I believe, from the Animal class API which was included with the Greenfoot download and can be imported into your project (menubar: Edit>Import Class...). I am not a fan of that class myself. Anyway, you can either subclass the Animal class with your Snake class (have Snake extend Animal), or just copy/paste the method from the Animal class into your Snake class and then remove the Animal class from your project.
duckduckduck duckduckduck

2014/2/9

#
Thank you!!!!
You need to login to post a reply.