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

2016/3/8

Create a new object from a different class

Bassusour Bassusour

2016/3/8

#
Hi again. So I want to create a new object, from an another class, at the same spot. My code is this, but I doesn't work. ND is the name of the class, i want to create an object from, and ND_dum is the class this method is located.
public void nd_missil()
    {
        if (Greenfoot.getRandomNumber(1000) == 5)
        {
            getWorld().addObject new (ND, setLocation(getX(), getY());
        }
    }
So how do i correct my code?
Super_Hippo Super_Hippo

2016/3/8

#
getWorld().addObject(new ND(), getX(), getY());
Bassusour Bassusour

2016/3/8

#
thank you :)
You need to login to post a reply.