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

2023/3/21

In need of help

JustAphochen JustAphochen

2023/3/21

#
How can I do it, that an Object gets Created again, after it got removed. An Object gets created at a Random spot and moves to the world border, when its there it gets removed. How can I get a new Object at another Random place so there is an infinte loop of spawning object that move to the border. Thank you in advance
danpost danpost

2023/3/22

#
JustAphochen wrote...
How can I do it, that an Object gets Created again, after it got removed. An Object gets created at a Random spot and moves to the world border, when its there it gets removed. How can I get a new Object at another Random place so there is an infinte loop of spawning object that move to the border.
Please show code for that object, plus what you attempted to spawn its instances (at least, how you spawn and add one into the world to begin with).
JustAphochen JustAphochen

2023/3/22

#
This one spawns the object in the world: this.addObject(new AutoB(), 1100, Greenfoot.getRandomNumber(600)); And this is the code of the objekt: public void act() { if(isTouching(Spieler.class)) { removeTouching(Spieler.class); Greenfoot.stop(); } move(-10); if (isAtEdge()) new AutoB(); if (isAtEdge()) getWorld().removeObject(this); }
danpost danpost

2023/3/23

#
JustAphochen wrote...
This one spawns the object in the world: << Code Omitted >> And this is the code of the objekt:
public void act()
{
    /** lines omitted */
    if (isAtEdge()) new AutoB(); 
    /** lines omitted */
}
The lines shown in act here will create an object of type AutoB, but nothing is done with that newly created object. It is not placed into the world, nor anything else. However, to save on everything, all around, it would be easiest just to relocate this object to some random spot at the starting edge:
if (isAtEdge()) setLocation(1100, Greenfoot.getRandomNumber(getWorld().getHeight()));
Remove the line after the given line in your code (the second isAtEdge check that removes this actor).
JustAphochen JustAphochen

2023/3/28

#
Thank you very much :)
You need to login to post a reply.