Hello Forum,
I am wondering if there is a simple way to grab the pixels around the edges of an irregular image that is accurate? I have been having a blast with the simplicity of color detection for moving collisions. It works great with simple Processing shapes. Now, I want to get this strategy going for imported images in the simplest way. I need a more accurate series of color detection points around the “player” image. (Mine are estimations and not consistent). I welcome any suggestions. Thank you!
PImage player;
PImage enemies;
//moving obstacle variable
int blackX1 = 200;
void setup(){
size(400, 400);
player = loadImage ("buggy.png");
enemies = loadImage ("badGuys.png");
}
void draw(){
rectMode (CENTER);
imageMode (CENTER);
background(255);
//obstacles
//enemy image has a 3 pixel black stroke for activating color detection
image (enemies, blackX1,300,100,100);
blackX1 = blackX1 + 6; //obstacle speed
if (blackX1 > 500) { //reset
blackX1 = -100;
}
image (player,mouseX,mouseY,100,100);
//detect color on 8 points around the player image (NOT ACCURATE)
int corner1 = get(-48+mouseX, 1+mouseY);
int corner2 = get(-27+mouseX, 22+mouseY);
int corner3 = get(-18+mouseX, -48+mouseY);
int corner4 = get (41+mouseX, -46+mouseY);
int center1 = get (43+mouseX, -16+mouseY);
int center2 = get (mouseX,50+mouseY);
int center3 = get (41+mouseX,28+mouseY);
int center4 = get (19+mouseX, 55+mouseY);
//if any of the "gets" grab a black pixel (3 pt stroke around enemy image) then report collision
if((corner1 == -16777216)||(corner2 == -16777216)||(corner3 == -16777216)||(corner4 == -16777216)
|| (center1 == -16777216) || (center2 == -16777216) || (center3 == -16777216)|| (center4 == -16777216)) {
fill (0);
textSize(24);
text ("collision", 20,20);
}
} //close draw