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

2012/2/12

getIntersectingObject() with multiple Actors.

fisch3r fisch3r

2012/2/12

#
Hello there! A quick question: I have two different actors, one for each player. One is controlled with the arrow keys, the other with A, W, S, D. I have a power up and I need it to disappear and play a sound while doing so whenever it's intersecting with one of the actors. This is easy if I only have one Bomberman.class. I simply can't get it to work with BOTH the Bomberman.class and the Bomberman2.class. This is my powerUp code:
public void act() 
    {
        //Deletes the powerup if it intersects with the Bomberman actor.
        Actor onePowerUp = getOneIntersectingObject(Bomberman.class);
        
        if (onePowerUp != null)
        {
            getWorld().removeObject(this);
            //The splooge.wav sound effect is then played.
            Greenfoot.playSound("splooge.wav");
        }
    }
programmer22 programmer22

2012/2/12

#
hmm i have an idea as to what u might be able to do just guessing tho .... try to put the code for intersecting in both actors "Bomber man1" and 2
fisch3r fisch3r

2012/2/12

#
How do you mean exactly? I tried Actor onePowerUp = getOneIntersectingObject(Bomberman.class, Bomberman2.class); but the compiler gave me an error.
programmer22 programmer22

2012/2/12

#
hmm well put in their that when the bomber man intersects with the object to play the noise in both ...
fisch3r fisch3r

2012/2/12

#
Got it working now. I had to move the code into each actor instead of having it in the PowerUp class.
programmer22 programmer22

2012/2/12

#
good good i was curious as to why it was in power up but was unsure
You need to login to post a reply.