Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package game;
- import java.io.IOException;
- import org.lwjgl.opengl.GL11;
- import org.newdawn.slick.opengl.Texture;
- import org.newdawn.slick.opengl.TextureLoader;
- import org.newdawn.slick.util.ResourceLoader;
- public class Sprite
- {
- protected Texture texture;
- protected float x;
- protected float y;
- private float textureX;
- private float textureY;
- public Sprite(String filename, float x, float y)
- {
- try
- {
- texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("game/" + filename));
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- this.x = x;
- this.y = y;
- textureX = (float)texture.getImageWidth()/texture.getTextureWidth();
- textureY = (float)texture.getImageHeight()/texture.getTextureHeight();
- }
- public void draw()
- {
- GL11.glPushMatrix();
- texture.bind();
- GL11.glTranslatef(x, y, 0);
- GL11.glBegin(GL11.GL_QUADS);
- {
- GL11.glTexCoord2f(0,0);
- GL11.glVertex2f(0,0);
- GL11.glTexCoord2f(textureX,0);
- GL11.glVertex2f(texture.getImageWidth(),0);
- GL11.glTexCoord2f(textureX,textureY);
- GL11.glVertex2f(texture.getImageWidth(),texture.getImageHeight());
- GL11.glTexCoord2f(0,textureY);
- GL11.glVertex2f(0,texture.getImageHeight());
- }
- GL11.glEnd();
- GL11.glPopMatrix();
- }
- //Getters
- public float getX()
- {
- return x;
- }
- public float getY()
- {
- return y;
- }
- //Setters
- public void setX(float x)
- {
- this.x = x;
- }
- public void setY(float y)
- {
- this.y = y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment