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

2017/5/27

Remove a class and use an other class to do her job

Phirippu Phirippu

2017/5/27

#
In my project i have a board, named "paddel", which is bouncing back a ball. Now i want remove the paddel when the variable s==48 und use the class "paddel2" to do the job of the "paddel" My problem is that it can not find symbol-class paddel2 in the last line
        
               if ( s == 48)
        {
            Actor paddel = getOneIntersectingObject(Paddel.class);
            getWorld().removeObject(paddel);
            Paddel2 paddel2 = new Paddel2();
            getWorld().addObject(new paddel2(), 240, 440);

        }
My 2. questino : I have some places like here where I want check out if the paddel hit the ball, which is flying around. Can I write the code like this:
if (getOneIntersectingObject(Paddel.class) != null || getOneIntersectingObject(Paddel.class) != null) {
            dy = -dy;
        }
danpost danpost

2017/5/27

#
Q 1: In last line, change 'new paddel2()' to 'paddel2', which is the declared name of the object reference variable from the previous line. Q 2: The second 'Paddel.class' should probably be 'Paddel2.class'. However, the following would be sufficient:
if (isTouching(Paddel.class) || isTouching(Paddel2.class))
Phirippu Phirippu

2017/5/27

#
Ok, that is working now. Thank you ! But now i have two new problems: Now the Paddel2 is there but the first Paddel is allso still there und the new Paddel2 has a variable length. If I move it with my arrowbuttons after the ball hit a block it will growi to a length from the start of the Paddel2 to the point where it hits the ball. If the Paddel hit the Wall it will decrease on the side on the Wall like the Wall is shreddering the Paddel2.
Phirippu Phirippu

2017/5/27

#
Can somebody see the misstake and help me ?
Yehuda Yehuda

2017/5/28

#
Problem 1: For the Paddle to be removed you need the ball to be touching the paddle when s == 48. If you want to remove all the paddles from the world (which will remove the one that's there), then you can do the following:
getWorld().removeObjects(getWorld().getObjects(Paddle.class));
// then add in the Paddle2
Problem 2: I can't help with what's happening with the Paddle2 with the code you gave, you need to show the full Paddle2 class code.
You need to login to post a reply.