Added a small and simple test EI.java. and fixed some buggs
This commit is contained in:
parent
bea0632d5d
commit
dbee794932
8 changed files with 150 additions and 53 deletions
|
|
@ -38,6 +38,18 @@ public class Sprite {
|
|||
location = new Vector2I(0,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.name = name;
|
||||
this.texture = texture;
|
||||
this.location = new Vector2I(texture.getImageWidth(),texture.getImageHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new sprite from a specified image.
|
||||
*
|
||||
|
|
@ -47,9 +59,9 @@ public class Sprite {
|
|||
public Sprite(String name, String ref) {
|
||||
try {
|
||||
this.name = name;
|
||||
texture = TextureLoader.getTextureLoaderInstance().getTexture(ref);
|
||||
this.texture = TextureLoader.getTextureLoaderInstance().getTexture(ref);
|
||||
|
||||
location = new Vector2I(texture.getImageWidth(),texture.getImageHeight());
|
||||
this.location = new Vector2I(texture.getImageWidth(),texture.getImageHeight());
|
||||
} catch (IOException e) {
|
||||
// a tad abrupt, but our purposes if you can't find a
|
||||
// sprite's image you might as well give up.
|
||||
|
|
@ -90,19 +102,17 @@ public class Sprite {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the height of this sprite in pixels
|
||||
* Get the Location of the sprite
|
||||
*
|
||||
* @return The height of this sprite in pixels
|
||||
* @return The Location of the sprite
|
||||
*/
|
||||
public int getLocation() {
|
||||
if(texture == null){
|
||||
return 0;
|
||||
}
|
||||
return texture.getImageHeight();
|
||||
public Vector2I getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the location of this sprite in pixels
|
||||
*
|
||||
* @param x The x coordinate of the sprite
|
||||
* @param y The y coordinate of the sprite
|
||||
*/
|
||||
|
|
@ -112,6 +122,7 @@ public class Sprite {
|
|||
|
||||
/**
|
||||
* set the location of this sprite in pixels
|
||||
*
|
||||
* @param v The location of the sprite
|
||||
*/
|
||||
public void setLocation(Vector2I v) {
|
||||
|
|
@ -124,28 +135,28 @@ public class Sprite {
|
|||
public void render() {
|
||||
// store the current model matrix
|
||||
GL11.glPushMatrix();
|
||||
|
||||
|
||||
// bind to the appropriate texture for this sprite
|
||||
texture.bind();
|
||||
|
||||
|
||||
// translate to the right location and prepare to draw
|
||||
GL11.glTranslatef(location.getX(), location.getY(), 0);
|
||||
GL11.glColor3f(1,1,1);
|
||||
|
||||
GL11.glColor3f(1,1,1);
|
||||
|
||||
// draw a quad textured to match the sprite
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
{
|
||||
GL11.glTexCoord2f(0, 0);
|
||||
GL11.glVertex2f(0, 0);
|
||||
GL11.glTexCoord2f(0, texture.getImageWidth());
|
||||
GL11.glVertex2f(0, texture.getImageHeight());
|
||||
GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
|
||||
GL11.glVertex2f(texture.getImageWidth(),texture.getImageHeight());
|
||||
GL11.glTexCoord2f(texture.getWidth(), 0);
|
||||
GL11.glVertex2f(texture.getImageWidth(),0);
|
||||
GL11.glTexCoord2f(0, 0);
|
||||
GL11.glVertex2f(0, 0);
|
||||
GL11.glTexCoord2f(0, texture.getHeight());
|
||||
GL11.glVertex2f(0, texture.getImageHeight());
|
||||
GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
|
||||
GL11.glVertex2f(texture.getImageWidth(),texture.getImageHeight());
|
||||
GL11.glTexCoord2f(texture.getWidth(), 0);
|
||||
GL11.glVertex2f(texture.getImageWidth(),0);
|
||||
}
|
||||
GL11.glEnd();
|
||||
|
||||
|
||||
// restore the model view matrix to prevent contamination
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue