Added methods to check for transparent pixels in images.

This is currently being used for the logo/play/exit buttons in the main menu.

Also fixed bug where mod multipliers weren't being read.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-02-19 15:05:55 -05:00
parent ab1a377be0
commit 80c66a98c3
10 changed files with 97 additions and 33 deletions

View File

@@ -24,7 +24,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
package org.newdawn.slick;
@@ -1407,6 +1407,36 @@ public class Image implements Renderable {
translate(pixelData[offset+2]));
}
}
/**
* Get the alpha value of a pixel at a specified location in this image,
* or 1f if the image does not support transparency.
*
* @param x The x coordinate of the pixel
* @param y The y coordinate of the pixel
* @return The alpha level of the pixel at the specified location
*/
public float getAlphaAt(int x, int y) {
if (!texture.hasAlpha())
return 1f;
if (pixelData == null)
pixelData = texture.getTextureData();
// scale coordinates based on the image scale
x = x * texture.getImageWidth() / width;
y = y * texture.getImageHeight() / height;
int xo = (int) (textureOffsetX * texture.getTextureWidth());
int yo = (int) (textureOffsetY * texture.getTextureHeight());
x = (textureWidth < 0) ? xo - x : xo + x;
y = (textureHeight < 0) ? yo - y : yo + y;
int offset = x + (y * texture.getTextureWidth());
offset *= 4;
return (offset + 3 >= pixelData.length) ? 1f : translate(pixelData[offset + 3]) / 255f;
}
/**
* Check if this image has been destroyed

View File

@@ -24,7 +24,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
package org.newdawn.slick;

View File

@@ -24,7 +24,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
package org.newdawn.slick.openal;

View File

@@ -24,7 +24,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
package org.newdawn.slick.openal;

View File

@@ -24,7 +24,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
package org.newdawn.slick.openal;

View File

@@ -24,7 +24,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
package org.newdawn.slick.openal;