package ei.engine.scene; import java.awt.Rectangle; import org.lwjgl.opengl.GL11; import ei.engine.math.Vector2f; import ei.engine.texture.Texture; import ei.engine.texture.TextureLoader; /** * Implementation of sprite that uses an OpenGL quad and a texture * to render a given image to the screen. * * @author Kevin Glass * @author Brian Matzon * @author Ziver Koc */ public class Sprite extends Entity { /** The texture that stores the image for this sprite */ private Texture texture; private Vector2f moveTo; /** * Create a new empty sprite * * @param window The window in which the sprite will be displayed * @param ref A reference to the image on which this sprite should be based */ public Sprite(String name) { super(name); texture = null; } /** * Create a new sprite from a specified texture. * * @param name The name of the sprite * @param texture The texture to use */ public Sprite(String name, Texture texture) { super(name); this.texture = texture; } /** * Create a new sprite from a specified image. * * @param name The name of the sprite * @param ref A reference to the image on which this sprite should be based */ public Sprite(String name, String ref) { super(name); this.texture = TextureLoader.getTextureLoaderInstance().getTexture(ref); } /** * Get the width of this sprite in pixels * * @return The width of this sprite in pixels */ public int getWidth() { if(texture == null){ return 0; } return texture.getImageWidth(); } /** * Get the height of this sprite in pixels * * @return The height of this sprite in pixels */ public int getHeight() { if(texture == null){ return 0; } return texture.getImageHeight(); } public void move(Vector2f vector) { moveTo = vector; } public void update() { if(moveTo!=null) { if(moveTo.getX()>getLocation().getX()) { getLocation().add(0.5f, 0f, 0f); } if(moveTo.getY()>getLocation().getY()) { getLocation().add(0f, 0.5f, 0f); } if(moveTo.getX()