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

2018/11/2

addObject method not working and I don't know why?

potatosnix potatosnix

2018/11/2

#
As in the title, I'm trying to add an object but the addObject method isn't working for some reason, not sure what I've done to accomplish that lol. I'm trying check if the 'hollowTurtle' is touching an object 'car' and if it is then despawn but if it isn't then spawn a 'turtle' at the location of the object 'hollowTurtle' and then remove the 'hollowTurtle'. Thank you for your time!
public class hollowTurtle extends Actor
{
    /**
     * Act - do whatever the turtle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        spawnTurtle();
    }   
    public void spawnTurtle()
    {
        if (isTouching(car.class))
        {
            getWorld().removeObject(this);
        }
        else
        {
            int turtleX = getX();
            int turtleY = getY();
            addObject(new turtle(), turtleX, turtleY);
            getWorld().removeObject(this);
        }
    }
}
danpost danpost

2018/11/2

#
potatosnix wrote...
I'm trying to add an object but the addObject method isn't working for some reason, not sure what I've done to accomplish that << Code Omitted >>
The addObject method is not an Actor class method.
potatosnix potatosnix

2018/11/4

#
danpost wrote...
potatosnix wrote...
I'm trying to add an object but the addObject method isn't working for some reason, not sure what I've done to accomplish that << Code Omitted >>
The addObject method is not an Actor class method.
Thank you, I didn't even think of that! All fixed and working, thank you so much!!
You need to login to post a reply.