All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.espressoengine.object.Sprite2D Maven / Gradle / Ivy

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); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy