2014-11-05 118 views
0

我想在點擊屏幕然後滑動ya動畫改變屏幕。 這段代碼一直只是改變圖像,但它沒有動畫。我想改變圖像上的點擊屏幕是動畫,然後改變..只有改變圖像是代碼是貝婁,但如何動畫是不知道?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)); 
} 

} 
+0

我要縮放動畫像Libgdx簡單的android這個鏈接的答案.. – Destro 2014-11-05 07:25:50

+0

我想要喜歡這個somthing .. https://www.youtube.com/watch?v=D_8WSbB0WQQ – Destro 2014-11-12 10:29:02

回答