io.github.espressoengine.object.Sprite2D Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of espresso Show documentation
Show all versions of espresso Show documentation
A simple and lightweight game engine for Java using Swing.
The newest version!
package io.github.espressoengine.object;
import java.awt.image.BufferedImage;
import java.io.File;
import java.awt.geom.Rectangle2D;
import java.awt.geom.AffineTransform;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* A 2D sprite.
*
* @author pastthepixels
* @version $Id: $Id
*/
public class Sprite2D extends Object {
// Image
public BufferedImage image;
/**
* Loads an image from a file path.
*
* @param path a {@link java.lang.String} object
*/
public void loadImage(String path) {
try {
image = ImageIO.read(new File(path));
} catch(IOException error) {
error.printStackTrace();
}
}
/** {@inheritDoc} */
public void updateBoundingBox(AffineTransform transform) {
this.boundingBox = transform.createTransformedShape(new Rectangle2D.Double(_enginePosition.x, _enginePosition.y, image.getWidth(), image.getHeight())).getBounds2D();
}
/**
* Constructor for Sprite2D.
*/
public Sprite2D() {
}
/**
* Constructor for Sprite2D with a file path for an image
*
* @param path a {@link java.lang.String} object
*/
public Sprite2D(String path) {
loadImage(path);
}
}