私のシナリオでは、特定のアクターにスプライトアニメーションを再生しようとしています。本を読むのに加えて、私はまた、 "FlappyBird"のゲームであるlibgdxを使って作成する方法に関するステップバイステップのチュートリアルも見ていました。これは、ビデオの男がやりたいことと同じことをしていると言っているわけではありません。私のステージでスプライトアニメーションが再生されない(Libgdx)
「フルーツ・スマッシュ」や「ビーズ・ジュエリー」のようなゲームを作ろうとしています。私は自分のメニューと自分のゲーム(またはチュートリアルのようなプレイステーション)を作成します。ステージのボックス(俳優)を管理するテーブルクラス(このクラスはステージを拡張します)も作成します。プログラムはすでにボックスをそれぞれの位置に配置し、各ボックスの座標を取得するので、ボックスをクリックした瞬間にゲームはどのボックスであるかを知ることができます。
今、いくつかのボックスのスプライトアニメーションを再現したい...しかし、私のテーブル(またはステージ)はアニメーションを再生しません。
マイBoxクラスはこれです:
public class Box extends Actor {
private Tipo tipo;
private boolean activo;
private String clase;
private TextureRegion region;
private float elapsedTime;
private Animation<TextureRegion> animacion,selected, unselected;
private Rectangle area;
private float velocidadY,velocidadX;
private int minY,minX,maxY,maxX;
public Box(){
super();
velocidadX = 0;
velocidadY = 0;
minY = 0;
minX = 0;
maxY = 0;
maxX = 0;
elapsedTime = 0;
activo = false;
region = new TextureRegion();
area = new Rectangle();
asignarTipo();
}
//HERE I ASSIGN THE TYPE OF EACH BOX
public void asignarTipo(){
Random rand = new Random();
int t = rand.nextInt((4-1)+1)+1;;
switch (t){
case 1:
tipo = Tipo.cbV2;
clase = "V2";
unselected = new Animation(0.2f,cargarSprites("1B",".png",1));
selected = new Animation(0.2f,cargarSprites("1",".png",2),Animation.PlayMode.LOOP_PINGPONG);
setAnimation(selected);
break;
case 2:
tipo = tipo.cbV4;
clase = "V4";
unselected = new Animation(0.2f,cargarSprites("2B",".png",1));
selected = new Animation(0.2f,cargarSprites("2",".png",2),Animation.PlayMode.LOOP_PINGPONG);
setAnimation(unselected);
break;
case 3:
tipo = tipo.cbV8;
clase = "V8";
unselected = new Animation(0.2f,cargarSprites("3B",".png",1));
selected = new Animation(0.2f,cargarSprites("3",".png",2),Animation.PlayMode.LOOP_PINGPONG);
setAnimation(unselected);
break;
case 4:
tipo = tipo.cbV16;
clase = "V16";
unselected = new Animation(0.2f,cargarSprites("4B",".png",1));
selected = new Animation(0.2f,cargarSprites("4",".png",2),Animation.PlayMode.LOOP_PINGPONG);
setAnimation(unselected);
break;
}
}
//setTexture
public void setTextura(Texture t){
int ancho = t.getWidth();
int alto = t.getHeight();
setWidth(ancho);
setHeight(alto);
region.setRegion(t);
}
//This function returns the sprite array
public Array<TextureRegion> cargarSprites(String imagen, String ext, int index){
TextureRegion frames[] = new TextureRegion[index];
for (int i = 0; i < index; i++){
if(imagen.length() < 2){
Texture t = new Texture(Gdx.files.internal(imagen + i + ext));
t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
frames[i] = new TextureRegion(t);
}else{
Texture t = new Texture(Gdx.files.internal(imagen + ext));
t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
frames[i] = new TextureRegion(t);
}
}
Array<TextureRegion> framesArray = new Array(frames);
return framesArray;
}
public void setAnimation(Animation<TextureRegion> a)
{
setTextura(a.getKeyFrame(0).getTexture());
animacion = a;
}
public Rectangle getBoundingRectangle(){
area.set(getX(),getY(),getWidth(),getHeight());
return area;
}
//Act method (or UPDATE)
public void Act(float dt){
super.act(dt);
elapsedTime += dt;
moveBy(velocidadX * dt, velocidadY * dt);
}
public void draw(Batch batch, float parentAlpha){
Color c = getColor();
batch.setColor(c.r, c.g, c.b, c.a);
region.setRegion(animacion.getKeyFrame(elapsedTime));
if (isVisible())
batch.draw(region, getX(), getY(), getOriginX(), getOriginY(),
getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
}
表クラス:
//I do a loop to render all the boxes of my table
public void updateTableObjects(float dt){
for(int f=0;f<baterias.length;f++){
for(int c=0;c<baterias[f].length;c++){
baterias[f][c].act(dt);
}
}
}
PlayStateクラス:ここ
public class PlayState extends Estado {
private Texture background;
private Tabla tabla;
protected PlayState(GameStateManager gsm) {
super(gsm);
tabla = new Tabla();
background = new Texture("fondo_juego.png");
camara.setToOrtho(true,background.getWidth(),background.getHeight());
Image fondo = new Image(background);
}
@Override
public void update(float dt) {
handleInput();
}
@Override
public void handleInput() {
if(Gdx.input.isTouched()){
raton.set(Gdx.input.getX(), Gdx.input.getY(),0);
camara.unproject(raton);
if(raton.x > 173 && raton.y < 703)
tabla.buscarCubo(raton.x,raton.y);
System.out.println((int)raton.x + "," + (int)raton.y);
}
}
//I THINK HERE IS THE PROBLEM... I TRY TO PLACE THE METHOD THAT UPDATES
//ALL THE BOXES OF THE TABLE, BUT DIDNT WORK
@Override
public void render(SpriteBatch batch) {
batch.begin();
batch.draw(background,0,0, game.ANCHO, game.ALTO);
batch.end();
tabla.act(Gdx.graphics.getDeltaTime());
tabla.updateTableObjects(Gdx.graphics.getDeltaTime());
tabla.draw();
}
}
いただきましたの?