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

2014/1/20

can i make 1 classactor with of the same images dissapear

Vigelandzoon Vigelandzoon

2014/1/20

#
Dear greenfoot followers i have the code to make them dissapear but thy dont work correctly
danpost danpost

2014/1/20

#
Do you mean to make all actors of the same class get removed from the world? or, put another way, what is wrong with 'worldReference.removeObjects(worldReference.getObjects(ActorClassName.class));'?
Vigelandzoon Vigelandzoon

2014/1/20

#
Yes all actors from the same class must dissapear if they are equal
Vigelandzoon Vigelandzoon

2014/1/20

#
if i click on a image and i find the other one the must dissapear
danpost danpost

2014/1/20

#
Can you show an example class of an object that is clicked on? And to clarify, only two objects are removed at a time...right?
Vigelandzoon Vigelandzoon

2014/1/20

#
public void opencard()

    {
        int duiker = 0;
        int duiker2 = 0;
        if (duiker == duiker2)
        {

            if(Greenfoot.mouseClicked(Duiker.class))
            {
                setImage("duiker_tcm46-175501.jpg");
                duiker = 1;
                if(Greenfoot.mouseClicked(duiker2))
                {
                    duiker2 = 1;

                }
                
                

                
                {
                    getWorld().removeObject(this);

                }

            }
            else if(Greenfoot.mouseClicked(this))
            {
               setImage("duiker_tcm46-175501.jpg");
               Greenfoot.delay(150);

              setImage("150px_RGB_WEBSAFE_D_B_G_26-29652.gif");

            }
        }
    }
danpost danpost

2014/1/20

#
I think the main problem is that most of this code should be in your world class. Also the fields 'duiker' and duiker2' should not be declared within the method but outside of it. Because lines 4 and 5 declare and set the value of both fields to zero, the 'if' condition on line 6 will always be true. Also, line 9 is flawed in that you cannot use a class as an argument in the 'mouseClicked' method and get the results you might expect. Basically, you cannot click on a class; you either click anywhere ('null'), in the world (on the World object) or on an Actor object.
Vigelandzoon Vigelandzoon

2014/1/20

#
Can you please provide me a code of which you are trying to explain I'm completely lost at this point. My english is not that good.
danpost danpost

2014/1/20

#
The line numbers refer to the code of which I refer to.
You need to login to post a reply.