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

2020/4/11

Hi .. i want to compare tow images of two classes by using the equals method but it doesn't work.could you say where i have the mistake please.

JojoAr JojoAr

2020/4/11

#
private void fire() 
    {
            addToVelocity(new Vector(getRotation(), 0.3));
            Ball4 bullet = new Ball4 ( getVelocity(), getRotation());            
            getWorld().addObject (bullet, getX(), getY()-50);                            
            bullet.setRotation(getRotation());
            bullet.move(40);
            bullet. changeig();
            Baba baba = new Baba();
            
            if (bullet.getImage().equals (Baba.class)){
                
                 getWorld().removeObject(this);
            }
             
            
           
           move(-speed);
            
        }
danpost danpost

2020/4/11

#
Maybe you meant ?this? for line 11:
if (bullet.getImage().equals(baba.getImage())){
JojoAr JojoAr

2020/4/11

#
I have already tried this but it didnt work.
danpost danpost

2020/4/11

#
JojoAr wrote...
it didnt work
That is way too vague -- just saying "it didn't work". Why are you comparing images? What are you trying to accomplish -- in general? Then be more specific as to how you want to go about accomplishing it.
JojoAr JojoAr

2020/4/11

#
I'm programing abubble shooter game in which i have a cannon at the bottom and two classes for bubbles one class is for bubbles that are already in the world and one class for the bubbles that come out from the cannon.so i want now to compare the bubble image that was fired from the cannon with the bubbles that are already in the world so that after touching if the bubble image from the cannon is the same as the bubble image that is in the world they will be removed. I hope that the problem is clear now.
danpost danpost

2020/4/12

#
JojoAr wrote...
I'm programing abubble shooter game in which i have a cannon at the bottom and two classes for bubbles one class is for bubbles that are already in the world and one class for the bubbles that come out from the cannon.so i want now to compare the bubble image that was fired from the cannon with the bubbles that are already in the world so that after touching if the bubble image from the cannon is the same as the bubble image that is in the world they will be removed. I hope that the problem is clear now.
Wouldn't just asking what type bubble it is be enough? --
if (isTouching(Baba.class))
You need to login to post a reply.