Я сделал обе возможности.
Так что я попробовал оба, и это кажется узаконительно быстрым. Мне нравится эта версия больше из-за простоты.
Как это работает, вы добавляете несколько файлов .PNG к использованию addTexture(String ts)
или addTexture(String ts, int num)
из другого класса. И хорошо остальное говорит само за себя. Я думаю, c:
package line.entity;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glTexCoord2f;
import static org.lwjgl.opengl.GL11.glTranslatef;
import static org.lwjgl.opengl.GL11.glVertex2f;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Timer;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class Animation extends Entity{
private ArrayList<Texture> textures;
private boolean ExtraBind = false;
public boolean Popped = false;
private float interval = 0.07f;
private int currentTexture = 0;
private String textForm = "PNG";
private Texture none;
private Timer texTime;
private Float[] c4f = {1f, 1f, 1f, 1f};
public Animation(float x, float y){
super(x, y);
}
public Animation(float x, float y, float w, float h){
super(x, y);
this.width = w;
this.height = h;
}
@Override
public void init() {
textures = new ArrayList<Texture>();
texTime = new Timer();
try {
none = TextureLoader.getTexture(textForm, getInputStream("/img/none.png"), true, GL11.GL_LINEAR);
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("static-access")
@Override
public void update() {
if(isPopped() == true){
texTime.tick();
if(texTime.getTime() > interval){
texTime.set(0);
if(currentTexture < textures.size()){
currentTexture++;
}
}
}else{
currentTexture = 0;
}
}
@Override
public void draw() {
if(currentTexture < textures.size()){
if(ExtraBind){
glBindTexture(GL_TEXTURE_2D, textures.get(currentTexture).getTextureID());
}else{
textures.get(currentTexture).bind();
}
}else{
if(ExtraBind){
glBindTexture(GL_TEXTURE_2D, none.getTextureID());
}else{
none.bind();
}
}
glColor4f(c4f[0], c4f[1], c4f[2], c4f[3]);;
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(x, y);
glTexCoord2f(1,0);
glVertex2f(x + width,y);
glTexCoord2f(1,1);
glVertex2f(x + width, y + height);
glTexCoord2f(0,1);
glVertex2f(x, y + height);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
}
public void addTexture(String ts){
try {
textures.add(TextureLoader.getTexture(textForm, getInputStream(ts), true, GL11.GL_LINEAR));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void addTexture(String ts, int num){
try {
textures.add(num, TextureLoader.getTexture(textForm, getInputStream(ts), true,GL11.GL_LINEAR));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private InputStream getInputStream(String string)
{
try
{
BufferedImage bi = ImageIO.read(this.getClass().getResource(string));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bi, "PNG", baos);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
return is;
} catch (IOException e)
{
System.out.println("Error: "+e);
}
return null;
}
}
Почему бы вам просто не сделать оба, а затем сами увидеть, что работает лучше всего? – Vallentin
Я сделал это внизу внизу –
Внизу внизу, где? – Vallentin