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

2013/5/29

Set Function Issue

toscany toscany

2013/5/29

#
I have this function
public void bulletHitsPlayer(){
         
         Bullet bullet = (Bullet)getOneIntersectingObject(Bullet.class);
         if(bullet != null){
             // int value
              life = -1;          
         }
          getLevel().setLifeOfPlayer(life);
     }
This method is called in the act function. The problem is that as long as the condition is true, it keeps add life to the setLifeOfplayer method. I just wanted it to happen once not in a loop. Hope someone is out to help me on this one. Thanks
Gevater_Tod4711 Gevater_Tod4711

2013/5/29

#
You could remove the bullet after executing this code. To remove the bullet use getWorld().removeObject(bullet);
toscany toscany

2013/5/29

#
@Gevatar, Thanks. I did not want to remove the bullet at that point though it will work if it is what I am planning to do
Gevater_Tod4711 Gevater_Tod4711

2013/5/30

#
If you don't want to remove the bullet it also is possible to make the bullet hurt your actor only one time. Than only a different bullet object could hurt your actor again. Would this be better for your game?
You need to login to post a reply.