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

2013/3/3

Need Help with Egoshooter

Abdi Abdi

2013/3/3

#
Hey Guys, im working on a project for school and i need your help. im programing some kind of egoshooter. There are some objects moving around and the user is managing a crosshair. Now i want the objects to disappear when the crosshair is on that object while im pressing the space bar. My idea: if (Greenfoot.isKeyDown("space")); { getWorld().removeObject(this); } also somehow the location of the crosshair has to be included but i dont know how to do it. Any suggestions?
danpost danpost

2013/3/3

#
The crosshair class code should detect the pressing of the spacebar and remove the intersecting object from the world.
Gevater_Tod4711 Gevater_Tod4711

2013/3/3

#
If you want to delete the objects your crosshair touches you should do it like this:
//in your crosshair class

public void act() {
    if (Greenfoot.isKeyDown("space")) {
        getWorld().removeObjects(getIntersectingObjects(Object.class));//instead of Object.class you have to add the classname of the objects you want to remove;
    }
}
Abdi Abdi

2013/3/3

#
thanks a lot it works now :)
You need to login to post a reply.