Libgdx-如何缩放动画

时间:2014-11-05 07:25:04

标签: java android libgdx

我想在点击屏幕然后幻灯片动画更改屏幕。 这段代码只是改变了图像,但它没有动画。我想更改屏幕上点击的图像是动画然后更改..只更改图像是代码是下面但但如何动画是不知道???

package com.check;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.utils.ArrayMap;


public class TutorialUI implements Screen, ApplicationListener{   
private static final String TEXTURE_PATH = "data/animvs-logo.png";  
private AssetManager assetManager;
private SpriteBatch batch;
private Stage stage;
private boolean tuchb=true;

private ArrayMap<Integer, Item> items;
private ArrayMap<Integer, Item> itemsDisplayed;

private Skin uiSkin;
private Table scrollTable;
private TextField textSearch; 
private String searchLastCriteria;    

TextButton button;
TextButtonStyle textButtonStyle;
TextureAtlas buttonAtlas;
BitmapFont font;
Texture logo,logo1,logo2;
  Window window;


@Override
public void create() {
    batch = new SpriteBatch();
    stage = new Stage();       
    items = new ArrayMap<Integer, Item>();
    itemsDisplayed = new ArrayMap<Integer, Item>();
    Gdx.input.setInputProcessor(this.stage);

      assetManager = new AssetManager();
      assetManager.load("data/animvs-logo.png", Texture.class);
      assetManager.load("data/uiskin.atlas", TextureAtlas.class);
      assetManager.finishLoading();     
    uiSkin = new Skin(Gdx.files.internal("data/uiskin.json"), assetManager.get("data/uiskin.atlas", TextureAtlas.class));       

    scrollTable = new Table();
    scrollTable.setCenterPosition(250, 400);    
    criaItens(10);


     window = new Window("Animvs - UI / ScrollPane Tutorial", uiSkin);    
     window.setBounds(0, 100, 500, 500); 
    textSearch = new TextField("", uiSkin);      
          textSearch.addListener(new InputListener() {
           public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.ENTER)
                rearrangeTable(); 
            return super.keyDown(event, keycode);
        }
    });             
    stage.addActor(scrollTable);
}   

 int tuch=1;
 @Override
 public void render() {

    stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 60f));

    Gdx.gl.glClearColor(0, 0.2f, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);       
    batch.begin();
    stage.draw();
    batch.end();

    if(Gdx.input.justTouched()){ 
        if(tuch<9 && tuchb){ 
             tuch=tuch+1;
         rearrangeTable();           
        }           
    }       
}  

@Override
public void resize(int width, int height) {
    batch.getProjectionMatrix().setToOrtho2D(0f, 0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
//        stage.setViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false); 
    rearrangeTable();
}

@Override
public void pause() {
}

@Override
public void resume() {
}

@Override
public void dispose() {
    // Don't forget to free unmanaged objects:

    batch.dispose();
    uiSkin.dispose();
    stage.dispose();
}

private final void criaItens(int total) {
    items.clear();
    itemsDisplayed.clear();

    for (int i = 0; i <total ; i++) {                     //   imagearr
        Color novaCor = new Color(MathUtils.random(0.5f), MathUtils.random(0.5f), MathUtils.random(0.5f), 1f);
        items.put(i, new Item(i, "Item " + i, assetManager.get(TEXTURE_PATH, Texture.class), novaCor, uiSkin));
//            items.put(i, new Item(i, "Item " + i,imagearr.get(i), novaCor, uiSkin));

    }
}   
private final void rearrangeTable() {
    scrollTable.clear(); 
    computeDisplayedItems(textSearch.getText());        
    for (int i = 0; i < tuch; i++) {               
            addImage(tuch);
            }
}   

public final void addImage(int indice) {

    scrollTable.add(itemsDisplayed.getValueAt(indice).getImage())
        .minHeight(500)  
        .minWidth(500)
        .center().expand();
}

private final void computeDisplayedItems(String searchCriteria) {
    if ((searchCriteria == null && searchLastCriteria == null) || searchCriteria.equals(searchLastCriteria)) {
        if (items.size != itemsDisplayed.size) {
            itemsDisplayed.clear();
            itemsDisplayed.putAll(items);
        }
        return;
    }

    itemsDisplayed.clear();

    if (searchCriteria == null || searchCriteria.isEmpty()) {
        itemsDisplayed.putAll(items);
        return;
    }

    for (int i = 0; i < items.size; i++) {

        if (items.getValueAt(i).getDescription().getText().toString().contains(searchCriteria))
            itemsDisplayed.put(items.getKeyAt(i), items.getValueAt(i));
    }

    searchLastCriteria = searchCriteria;
}

@Override
public void render(float delta) {
    // TODO Auto-generated method stub

}

@Override
public void show() {
    // TODO Auto-generated method stub

}

@Override
public void hide() {
    // TODO Auto-generated method stub

}
}

另一个班......

package com.check;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;


public final class Item {

private final class ImageClick extends ClickListener {
    private Item item;

    public ImageClick(Item item) {
        this.item = item;
    }

    public void clicked(InputEvent event, float x, float y) {
        if(item.getId()==0){
//          game.setScreen(new PowerScreen(game));  
        }

        Gdx.app.log("SELECTED ITEM", "ID: " + item.getId() + " Description: " + item.getDescription().getText());
    }
}

private int id;
private Label description;
private Image image;
private Color color;

public final int getId() {
    return id;
}

public final Label getDescription() {
    return description;
}

public final Image getImage() {
    return image;
}

public final Color getColor() {
    return color;
}

public Item(int index, String description, Texture texture, Color color, Skin skin) {

    this.id = index;
    this.description = new Label(description, skin);
    this.image = new Image(texture);
    this.color = color;         
    image.setColor(color); 
    image.addListener(new ImageClick(this));
}

}

1 个答案:

答案 0 :(得分:1)

请参阅此问题的此链接的答案https://github.com/krustnic/HorizontalSlidingPane