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

2013/2/19

Spawn Asteroids, that "fall down"!

1
2
Korgaz Korgaz

2013/2/19

#
Thank you, that worked now, these methods ind of deleted each other, so if the asteroid got spawned it immediately deleted itself.
danpost danpost

2013/2/19

#
Yeah, I know what is it. The Animal class uses a buffer (I think 20 pixels) by each edge to remove the object in. Remove the Animal class from your project. Have your Asteroid_Small class extend Actor. Put the 'Remove();' statement back in the Asteroid_Small class code. In the Asteroid_Small class: change line 24 from 'if (atWorldEdge())' to 'if(getY()==getWorld().getWidth()-1)'
Korgaz Korgaz

2013/2/19

#
Thank you, that helped a lot
danpost danpost

2013/2/19

#
danpost wrote...
In the Asteroid_Small class: change line 24 from 'if (atWorldEdge())' to 'if(getY()==getWorld().getWidth()-1)'
Sorry, not 'getWidth()' but 'getHeight()'.
Game/maniac Game/maniac

2013/2/19

#
or do this:
public void act()     
{    
    if(Greenfoot.getRandomNumber(200) < 50) {    
        addObject(new Asteroid_Small(), Greenfoot.getRandomNumber(519),0);     
    }    
}
danpost danpost

2013/2/19

#
Or do this:
public void act()     
{    
    if(Greenfoot.getRandomNumber(200) < 5)
    {    
        addObject(new Asteroid_Small(), Greenfoot.getRandomNumber(519),0);     
    }    
}
Game/maniac Game/maniac

2013/2/19

#
Or do this:
public void act()       
{      
    if(Greenfoot.getRandomNumber(200) < 5)  
    {      
        addObject(new Asteroid_Small(), Greenfoot.getRandomNumber(519),21);       
    }      
}
forgot to edit it
Game/maniac Game/maniac

2013/2/19

#
danpost wrote...
Or do this:
public void act()     
{    
    if(Greenfoot.getRandomNumber(200) < 5)
    {    
        addObject(new Asteroid_Small(), Greenfoot.getRandomNumber(519),0);     
    }    
}
lol I see you made the same mistake when trying to correct me
danpost danpost

2013/2/20

#
I was not trying to correct you. I was just trying to put the spawn rate back to the initial setting (which was 50:2000, and i changed to 5:200; and could even be 1:40). I had not realized what you were trying to do until you re-posted on that code. I see now you were changing the spawning y-coordinate so that it does not get removed near the top of the screen. That would have been a simple fix; however, to tell you the truth, I do not particularly care for the Animal class code because it does not take into account the actual size of the object. If the object was very tall, then it would still go partially above and below the world edge before disappearing, and small object disappear before the edge is reached. Besides, it only has like three very short methods which does not hurt much to have in the class that is sub-classing it; and then be modified to suit the specific actor.
You need to login to post a reply.
1
2