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

2011/12/19

need help making things disappear

jdemshki jdemshki

2011/12/19

#
so I've been going pretty good for a while. i now have an actor shooting something at another thing. how do i get the projectile to disappear? both on contact and if it hits the edge of the world. i used the code the tutorial provides to make the object disappear when my projectile hits it. i tried using this same thing to get the projectile to disappear when it hit the object but it isn't happening. i could really use some help.
danpost danpost

2011/12/20

#
What code do you have so far?
jdemshki jdemshki

2011/12/20

#
do you mean for the entire thing, or just the disappearing of my bomb?
danpost danpost

2011/12/20

#
Just what might be important to solve your issue. At least what code you have as far as TRYING to make the objects do what you want them to do. (the code you have for checking edge of world and removing the object, plus the code you have for hitting an object and trying to make it disappear then).
jdemshki jdemshki

2011/12/20

#
i have no code for checking the edge of the world, i don't know how to do that. if ("space".equals(Greenfoot.getKey())) { fire() ; } } } /** * Fire the lemur */ private void fire() { Bomb bomb = new Bomb() ; getWorld().addObject(bomb, getX(), getY()) ; bomb.setRotation(getRotation()); bomb.move(30.0); } this is what i use to make the projectile(bomb) fire.(i took it from the video showing it) public void act() { move(10.0) ; disappear() ; } public void disappear() { Actor castle; castle = getOneObjectAtOffset(0, 0, Castle.class) ; if (castle != null) { World world; world = getWorld(); world.removeObject(castle); } } this is what makes the object(the castle in my case) disappear when the projectile(the bomb in my case) hits it. what my goal is is to make the bomb disappear when it makes the castle disappear and when it hits the edge of the world. i tried using the same code to do it but it won't work. unfortunately, i got really frustrated earlier when it wouldn't work and i erased it to "try" and do something else. it was about this time i realized i needed some help.
danpost danpost

2011/12/20

#
If the act and disappear methods are in the Bomb class then immediately after world.removeObject(castle); in disappear add the line world.removeObject(this);.
jdemshki jdemshki

2011/12/20

#
Thank you so much!!! hahaha worked perfectly. what about for the edge of the world?
jdemshki jdemshki

2011/12/20

#
if (this.atWorldEdge()) {World world; world = getWorld(); world.removeObject(this); so i used this to get it to disappear at the edge, and it worked. the only problem is that an error message now shows up. this is all coded in the Bomb class.
danpost danpost

2011/12/20

#
What is does the error message say? (copy and paste it to the site, it probably shows where to problem is).
b321234 b321234

2011/12/20

#
Wow I ddn know there was an atWorldEdge API... I use another one. It's like public boolean checkEdge(int y){ boolean removed = false; if (y < getWorld().getHeight()-599) { getWorld().removeObject(this); removed = true; } else removed = false; return removed; } You can also do a getX() one, just change the getHeight() into getWidth()
jdemshki jdemshki

2011/12/20

#
forgot to specify: it only happens when it hits a castle and makes it disappear. it is working perfectly if it hits the edge of the world. java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:656) at greenfoot.Actor.getX(Actor.java:157) at Mover.atWorldEdge(Mover.java:70) at Bomb.disappear(Bomb.java:31) at Bomb.act(Bomb.java:18) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194)
jdemshki jdemshki

2011/12/20

#
I fixed it!!! public void disappear() { Actor castle; castle = getOneObjectAtOffset(0, 0, Castle.class) ; Actor bomb; bomb = getOneObjectAtOffset(0, 0, Bomb.class) ; if (castle != null) { World world; world = getWorld(); world.removeObject(castle); world.removeObject(bomb); } { if (this.atWorldEdge()) {World world; world = getWorld(); world.removeObject(this); } } } instead of removing "this" when the bomb hit the castle, i told it to remove "bomb" and i declared (i think thats the terminology) the bomb as the Bomb class
BradH BradH

2012/10/26

#
Actor fly; fly = getOneObjectAtOffset(0, 0, fly.class); if (fly != null) { World world; world = getWorld(); world.removeObject(fly); world.removeObject(this); Greenfoot.playSound("popbomb2.wav"); } I have this code to remove a projectile from the world once it destroys an enemy, but whenever it destroys an enemy the game just pauses and you have to press play to resume it (this happens everytime) any help?
Gevater_Tod4711 Gevater_Tod4711

2012/10/27

#
in this topic I already answered your question.
You need to login to post a reply.