We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a class AlienPod:
public class AlienPod {
public Globals globals = new Globals();
public float xPos, yPos;
public float Width, Height;
public float travelDistance;
public boolean isActive = false;
public AlienPod (float xin, float yin, float travelin) {
xPos = xin;
yPos = yin;
travelDistance = travelin;
Width = globals.alienIcon.width;
Height = globals.alienIcon.height;
}
public void activate () {
this.isActive = true;
}
public void deactivate () {
this.isActive = false;
}
public void moveToward (float towardX, float towardY) {
this.xPos = this.xPos + (( this.xPos < towardX ) * this.travelDistance ) - (( this.xPos > towardX ) * this.travelDistance );
this.yPos = this.yPos + (( this.yPos < towardY ) * this.travelDistance ) - (( this.yPos > towardY ) * this.travelDistance );
}
}
However an error occurs at
this.xPos = this.xPos + (( this.xPos < towardX ) * this.travelDistance ) - (( this.xPos > towardX ) * this.travelDistance );
All data types appear to be float, so I'm lost.
Thanks
Answers
I just realized my error,
( this.xPos < towardX )
returns a boolean, so I'll need to convert it to a float.you use < and >
which returns boolean
do you mean
-
instead of<
maybe?Use int() in order to convert the
boolean
expression to either0
or1
:https://Processing.org/reference/intconvert_.html
However, now I realize I can't cast from boolean to float
Oh, thanks very much GoToLoop
i'd write it out in full - it'll be clearer to other people / yourself in the future
(you only need the 'this.' if there's confusion between the class members and parameter names)
(and a += b is equiv to a = a + b)
much better than the totally unclear previous version....
(Especially now I've fixed the syntax error)
;-)