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

2013/2/22

cannot find symbol - constructor...

Mepp Mepp

2013/2/22

#
Hi, guys! Could someone say me, what’s wrong there and how to solve it? I just tried some things, but i don’t know exactly, what greenfoot want’s, the constructor is existing... And how can i let Greenfoot set an Actor (optical) over another?
Jonas234 Jonas234

2013/2/22

#
i guess the constructor of your Wallpiece Class is missing in the WP_Hard Class. try something like:
1
super(0, sp, world);
In the Constructor of your WP_Hard. Where 0 ist your Integer and world is an object of your Spielfeld. (I hope this will fix your error) Jonas
Mepp Mepp

2013/2/22

#
I tried it, but now he says: world is not public in greenfoot.Actor; cannot be accessed from outside package
Jonas234 Jonas234

2013/2/22

#
no world was just an example you need to replace world with the object of your current World. So in your case you need to write the object of Spielfeld in there. Jonas
danpost danpost

2013/2/22

#
It appears it is looking for a Wallpiece constructor with NO parameters. Either you are using 'new WP_Hard()' (with no parameters), or you need to add an empty constructor in the Wallpiece class.
1
2
3
public Wallpiece()
{
}
You do not have to re-declare 'Spieler spieler;' in the WP_Hard class as it is inherited from the Wallpiece class. I really do not see a need for the WP_Hard sub-class of Wallpiece. I would remove that class altogether; then, in the Wallpiece class, I would remove 'Spielfeld spf;', change the constructor declaration to 'public Wallpiece(int t, Spieler spieler)', remove the 'spf = spielfeld;' line from the constructor and remove the creation and adding of a new WP_Hard object from the act method. I am not sure if you actually meant '!=' in the 'if (getOneIntersectingObject(Spieler.class) == null)' command. To control the paint order to have one type of object visually over another, use the 'setPaintOrder' method found in the World class API.
Mepp Mepp

2013/2/23

#
Thanks for setPaintOrder, it worked perfect! I removed WP_Hard now, but i still have a problem: I have two objects of the class "Spieler", they move with the speed 3 and then create a wallpiece at their actual location:
1
2
3
move(3);
Wallpiece wp=new Wallpiece(1,this,spf);
spf.addObject(wp, getX(), getY());
The Spielers can also turn and if they touch a Wallpiece of one of the both, they should change their image, but the problem is, if they create one at their actual location, they must touch it. I tried to make a boolean in Wallpiece, that changes to false if they stop touching a Spieler for the first time, but the bad thing is, that i can’t let the Spieler ask, if athe specific boolean of the one Wallpiece they touched changed to false, because they just know the one that they created last. I thinked of naming the Wallpieces (wp ’s) with numbers, like wp1, wp2,... and then, if they collide i would let the Spieler ask which Wallpiece he touched and if this one has the one boolean at false, but i don’t know how to combinate the names with integers.
Jonas234 Jonas234

2013/2/23

#
you can do sth. like this:
1
2
3
4
5
6
7
8
ArrayList<Wallpiece> collisionList = getIntersectingObjects(Wallpiece.class);
for(Wallpiece collisionObject : collisionList)
{
if(!collisionObject.isFirstColliding())
{
// the Method you want to call
}
}
getIntersectingObject returns all Objects of a specific Class that intersect your actor. And then you just use a loop over all the Objects and you are checking if anyone of them has false as the value (the isFirstColliding() Method). The way you want to do it would be with an ArrayList where you add every new Object into the list and check them afterwards. Jonas
danpost danpost

2013/2/23

#
I am wondering why it would matter whether that Spieler had just created it or not. Maybe you should be more explicit as to how the coloring should work. If one Spieler object creates Wallpiece objects of one color and changes Wallpiece objects to that same color and the other does the same with a different color, then it should not matter if one RE-paints a Wallpiece object it just created.
Mepp Mepp

2013/2/24

#
Tried it, but it says:
1
2
3
4
5
6
7
8
9
ArrayList<Wallpiece> collisionList = getIntersectingObjects(Wallpiece.class);
for(Wallpiece collisionObject : collisionList){ 
      if(collisionObject.fresh==false){
           dead=true;
           setImage("Explosion.png");
           System.out.println(op + " hat gewonnen!");
           Greenfoot.stop();
      
}
incompatible types - found java.util.List but expected java.util.ArrayList<Wallpiece> It marked the Wallpiece.class in the brackets.
danpost danpost

2013/2/24

#
You have to cast the return from 'getIntersectingObject(Wallpiece.class)' with '(ArrayList<Wallpiece>)'. You can avoid having to import the List and ArrayList classes by adjusting the code.
1
2
3
4
5
6
7
8
9
10
11
for (Object obj : getIntersectingObjects(Wallpiece.class))
{
    Wallpiece wallpiece = (Wallpiece) obj; 
    if(!wallpiece.fresh)
    {
        dead=true;
        setImage("Explosion.png");
        System.out.println(op + " hat gewonnen!");
        Greenfoot.stop();
    
}
Mepp Mepp

2013/2/24

#
Thanks, It worked fine now!
You need to login to post a reply.