I'm creating "maps" for a game I'm making, and it's working fine on <=Android 2.1, but 2.2 is causing problems.
I'm not sure if this is a common method, so I'll explain what I'm doing. First, I draw the map which the user is going to see then I draw a map of identical size with nothing but white and pink (0xffFF006E). Anywhere I draw the pink color is an area/boundary I don't want the player to be able to enter/cross.
So, in-game, the regular map is constantly being drawn and the "bordermap" with the pink color is loaded into a Bitmap (but never actually drawn). To see if the player is attempting to cross a border, I check the player's x,y pos against the bordermap:
private boolean overBorder(int x, int y){
//The int 'COLOR_border' is predefined as 0xffFF006E
if(mPlayerDirection == UP && mMapBorders.getPixel(x, y-mPlayerHeight/2) == COLOR_border)return true;
if(mPlayerDirection == DOWN && mMapBorders.getPixel(x, y+mPlayerHeight/2) == COLOR_border)return true;
if(mPlayerDirection == LEFT && mMapBorders.getPixel(x-mPlayerWidth/2, y) == COLOR_border)return true;
if(mPlayerDirection == RIGHT && mMapBorders.getPixel(x+mPlayerWidth/2, y) == COLOR_border)return true;
//If those fail, false
return false;
}
If that code returns true, I stop the player. Like I said, this works excellently pre-2.2. If anyone has any insight on how to fix 2.2 compatibility I would appreciate it greatly.