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

2017/2/27

How can I create new instances of an object?

NussNinja NussNinja

2017/2/27

#
Hello, for a project I need to create a new instance of an object on a particular place. For example: A ant (actor) is crawling over the surface and wherever it goes, it leaves traces (also actor). So the "trace" actors have to be created where the ant is. I've already tried this, but it didn't work: Actor Ant = new Actor(); addObject(Ant, 100, 50); Error message: "cannot find symbol - method addObject(greenfoot.actor,int,int)". Can anyone tell me my mistake or another method to solve this problem?
Nosson1459 Nosson1459

2017/2/27

#
When you want to add this trace from Ant you could do:
1
2
// in place that you want to leave a trace
getWorld().addObject(new Trace(), getX(), getY()); // with correct constructor for your trace class
.
You need to login to post a reply.