OpenFL bitmapData.getPixel32始终返回0

问题描述

我正在尝试使用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;
    }
}

我的image.png:

enter image description here

解决方法

有趣的是,它看起来没有问题,而不是使用getPixel32和getPixels:

 public isEmpty(x: number,y: number): boolean {
        return (this.bitmapData.getPixels(new Rectangle(x,y,1,1)).get(3)) <= 150;
    }

但是我不知道这是否是最好的方法

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...