在 libgdx 中使用补间缩放演员。
package com.vector.science11;
import aurelienribon.tweenengine.Timeline;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenManager;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
public class Test3Dline extends ApplicationAdapter {
private SpriteBatch batch;
private OrthographicCamera orthoCamera;
private TweenManager tweenManager;
public Stage stage;
private Color bgColor;
SpriteDrawable spriteDrawable;
@Override
public void create() {
orthoCamera = new OrthographicCamera(960, 540);
orthoCamera.position.set(960 / 2, 540 / 2, 0);
orthoCamera.update();
bgColor = Color.valueOf("ffffff");
tweenManager = new TweenManager();
stage = new Stage();
stage.getViewport().setCamera(orthoCamera);
batch = new SpriteBatch();
Tween.registerAccessor(Actor.class, new ActorAccessors());
Image image1 = new Image(createTexture(50, 30, Color.RED, 1));
image1.setPosition(100, 100);
stage.addActor(image1);
Gdx.input.setInputProcessor(stage);
Timeline.createSequence()
.delay(2f)
.push(Tween.to(image1, ActorAccessors.SCALE_XY, 0.4f).target(2,
2))
.pushPause(3f)
.push(Tween.to(image1, ActorAccessors.SCALE_XY, 0.4f).target(1,
1)).start(tweenManager);
}
@Override
public void render() {
tweenManager.update(Gdx.graphics.getDeltaTime());
Gdx.gl.glClearColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(orthoCamera.combined);
stage.draw();
stage.act(Gdx.graphics.getDeltaTime());
// Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
}
public static Texture createTexture(int width, int height, Color col,
float alfa) {
Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
Color color = col;
pixmap.setColor(color.r, color.g, color.b, alfa);
pixmap.fillRectangle(0, 0, width, height);
Texture pixmaptexture = new Texture(pixmap);
return pixmaptexture;
}
}
并使用 Scene2D API,Action 方法:
package com.vector.science11;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
public class Test3Dline extends ApplicationAdapter {
private SpriteBatch batch;
private OrthographicCamera orthoCamera;
public Stage stage;
private Color bgColor;
SpriteDrawable spriteDrawable;
@Override
public void create() {
orthoCamera = new OrthographicCamera(960, 540);
orthoCamera.position.set(960 / 2, 540 / 2, 0);
orthoCamera.update();
bgColor = Color.valueOf("ffffff");
stage = new Stage();
stage.getViewport().setCamera(orthoCamera);
batch = new SpriteBatch();
Image image1 = new Image(createTexture(50, 30, Color.RED, 1));
image1.setPosition(100, 100);
stage.addActor(image1);
image1.addAction(Actions.sequence(Actions.scaleTo(2, 2, 2), // scale to
// 2 times
// of actual
// size
Actions.scaleTo(1, 1, 2) // come to original size
));
}
@Override
public void render() {
Gdx.gl.glClearColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(orthoCamera.combined);
stage.draw();
stage.act(Gdx.graphics.getDeltaTime());
}
public static Texture createTexture(int width, int height, Color col,
float alfa) {
Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
Color color = col;
pixmap.setColor(color.r, color.g, color.b, alfa);
pixmap.fillRectangle(0, 0, width, height);
Texture pixmaptexture = new Texture(pixmap);
return pixmaptexture;
}
}