How do i have an actor detect if it is on a certain color (in the background, in other actors, etc.) and also (In a different way) detect if a color is near them


1 2 3 4 | if (getColor(getX(), getY() == /*what do i put here?*/ ) { //the stuff i want to do } |
1 2 3 4 5 | GreenfootImage img = ...; //the image you want to check; Color color = ...; //the color you want to check; if (img.getColorAt(x, y).equals(color)) { //at the position you searched you have found the color you wanted; } |
1 | GreenfootImage img = ...; //the image you want to check; |
1 | GreenfootImage img = getImage(); |
1 | GreenfootImage img = getBackground(); |
1 2 3 4 5 6 7 8 9 10 | GreenfootImage img = Beam.img; //the image you want to check; Color color = Color.green; //the color you want to check; if (img.getColorAt(getX(), getY()).equals(color)) { canMove = false ; } else { canMove = true ; } |
1 2 3 4 | //i have this variable declared public static GreenfootImage img; //then in act i have this img = getImage(); |
1 | if (color.equals(img.getColorAt(getX(), getY()))) |