日期:2014-05-20  浏览次数:20748 次

关于MIDP2.0下像数碰撞如何获取碰撞点的坐标
看了SPRITE类后,发现它里面有一个方法(如下),能计算出碰撞点的坐标,但是这个方法是私有的,我该如何调用这个方法呢?如果重写该方法,transform1,transform2是多少呢?

 private static boolean doPixelCollision(int image1XOffset,
  int image1YOffset,
  int image2XOffset,
  int image2YOffset,
  Image image1, int transform1, 
  Image image2, int transform2,
  int width, int height) {

 // starting point of comparison
 int startY1;
 // x and y increments
 int xIncr1, yIncr1;

 // .. for image 2
 int startY2;
 int xIncr2, yIncr2;

 int numPixels = height * width;

 int[] argbData1 = new int[numPixels];
 int[] argbData2 = new int[numPixels];

 if (0x0 != (transform1 & INVERTED_AXES)) {
  // inverted axes

  // scanlength = height

  if (0x0 != (transform1 & Y_FLIP)) {
  xIncr1 = -(height); // - scanlength

  startY1 = numPixels - height; // numPixels - scanlength
  } else {
  xIncr1 = height; // + scanlength
  
  startY1 = 0;
  }

  if (0x0 != (transform1 & X_FLIP)) {
  yIncr1 = -1;

  startY1 += (height - 1);
  } else {
  yIncr1 = +1;
  }

  image1.getRGB(argbData1, 0, height, // scanlength = height
  image1XOffset, image1YOffset, height, width);

 } else {

  // scanlength = width

  if (0x0 != (transform1 & Y_FLIP)) {

  startY1 = numPixels - width; // numPixels - scanlength

  yIncr1 = -(width); // - scanlength
  } else {
  startY1 = 0;

  yIncr1 = width; // + scanlength
  }

  if (0x0 != (transform1 & X_FLIP)) {
  xIncr1 = -1;

  startY1 += (width - 1);
  } else {
  xIncr1 = +1;
  }

  image1.getRGB(argbData1, 0, width, // scanlength = width
  image1XOffset, image1YOffset, width, height);

 }


 if (0x0 != (transform2 & INVERTED_AXES)) {
  // inverted axes

  if (0x0 != (transform2 & Y_FLIP)) {
  xIncr2 = -(height);

  startY2 = numPixels - height;
  } else {
  xIncr2 = height;

  startY2 = 0;
  }

  if (0x0 != (transform2 & X_FLIP)) {
  yIncr2 = -1;
  
  startY2 += height - 1;
  } else {
  yIncr2 = +1;
  }

  image2.getRGB(argbData2, 0, height,
  image2XOffset, image2YOffset, height, width);

 } else {

  if (0x0 != (transform2 & Y_FLIP)) {
  startY2 = numPixels - width;

  yIncr2 = -(width);
  } else {
  startY2 = 0;

  yIncr2 = +width;
  }

  if (0x0 != (transform2 & X_FLIP)) {
  xIncr2 = -1;

  startY2 += (width - 1);
  } else {
  xIncr2 = +1;
  }

  image2.getRGB(argbData2, 0, width,
  image2XOffset, image2YOffset, width, height);

 }


 int x1, x2;
 int xLocalBegin1, xLocalBegin2;

 // the loop counters
 int numIterRows;
 int numIterColumns;

 for (numIterRows = 0, xLocalBegin1 = startY1, xLocalBegin2 = startY2;
  numIterRows < height;
  xLocalBegin1 += yIncr1, xLocalBegin2 += yIncr2, numIterRows++) {