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

2013/8/12

Move double distances

Kartoffelbrot Kartoffelbrot

2013/8/12

#
Can I move only 0.5 pixels, so that my Actor only will move one pixel every two acts or do I have to implement a timer therefore? I mean something like this: move(0.5);
Gevater_Tod4711 Gevater_Tod4711

2013/8/12

#
If you add some new fields to your actor like double exactX and double exactY you can make your actor move 0.5 cells. Your actor will not realy move 0.5 cells because greenfoot can't set an actor between two fields. But your actor will move 1 cell every two acts. Try using this:
1
2
3
4
5
6
7
8
9
protected double exactX;
protected double exactY;
 
@Override
public void setLocation(double exactX, double exactY) {
    this.exactX = exactX;
    this.exactY = exactY;
    super.setLocation((int) exactX, (int) exactY);
}
When you use double values for the location of the actors and override the setLocation method it should work.
Kartoffelbrot Kartoffelbrot

2013/8/12

#
I never knew how to override methods. Interesting to see. Thank you! What does protected mean?
Gevater_Tod4711 Gevater_Tod4711

2013/8/12

#
protected is a java modifyer which like public or private. Variables that are declared public are visible from everywhere in your code. A private declaration means that you can not access the variable or method from outside the class they are declared. Protected means that you can't access the variable from outside the class but the variable will be inherited so the methods or fields that are declared protected are visible in all subclasses of the class where the variables are. The variables are also inherited to outside packages. The last modifyer is the default modifyer (when you just declare a mehtod like: void setLocation(...)); The only difference between default and protected is that default is not inherited into outside packages.
Kartoffelbrot Kartoffelbrot

2013/8/12

#
Danke, schön wie wir uns immer auf englisch unterhalten.
Gevater_Tod4711 Gevater_Tod4711

2013/8/12

#
Ja ist eigentlich überflüssig. Aber so können auch andere das verstehen was wir hier erzählen.
Kartoffelbrot Kartoffelbrot

2013/8/12

#
Dachte ich mir auch :)
danpost danpost

2013/8/12

#
Actually, to override a method, it not only needs the same name, but also the same number of arguments and the order of the type of the arguments must also be the same. Therefore, since the method signature 'setLocation(double, double)' is not the same as 'setLocation(int, int)', one does not override the other. Please refer to the java tutorial pages on Classes and Objects, especially to the part on Methods.
Kartoffelbrot Kartoffelbrot

2013/8/12

#
Yes, master! ;D
You need to login to post a reply.