问题描述
我正在尝试使用OpenFL框架中的 getPixel32 来确定某个位置是否存在空像素,但它始终返回0。
这是我的代码:
import { Bitmap,BitmapData } from "openfl";
export default class Tile extends Bitmap {
constructor(param1: BitmapData) {
super(param1);
}
public isEmpty(x: number,y: number): boolean {
const pixel32 = this.bitmapData.getPixel32(x,y);
console.log(pixel32); // return 0
return ((pixel32 >> 24) & 255) <= 150;
}
}
解决方法
有趣的是,它看起来没有问题,而不是使用getPixel32和getPixels:
public isEmpty(x: number,y: number): boolean {
return (this.bitmapData.getPixels(new Rectangle(x,y,1,1)).get(3)) <= 150;
}
但是我不知道这是否是最好的方法