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

2012/6/1

checking if object is in world

h123n h123n

2012/6/1

#
Hi I have got a problem with my code because I need to make a simple method that checks if an object is in world. code for bear.class
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class bear here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class bear extends Actor
{
    /**
     * Act - do whatever the bear wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private int range = 0;

    public void act()
    {
        if//object is in world. code needed here.
        {
            poorpig pig = (poorpig)getWorld().getObjects(poorpig.class).get(0);  
            getWorld().getObjects(poorpig.class).get(0);
        }
    }
}
davmac davmac

2012/6/1

#
if (getWorld() != null) { ...
You need to login to post a reply.