libgdx的基本使用——演员与演出

来源:互联网 发布:淘宝二手工作站靠谱吗 编辑:程序博客网 时间:2024/04/28 23:32

直接贴本demo的核心代码,如果有什么不明白的,请参考前面的博客

package com.doodle.rdemo3;import com.badlogic.gdx.ApplicationListener;import com.badlogic.gdx.Gdx;import com.badlogic.gdx.graphics.GL10;import com.badlogic.gdx.graphics.Texture;import com.badlogic.gdx.graphics.Texture.TextureFilter;import com.badlogic.gdx.math.MathUtils;import com.badlogic.gdx.scenes.scene2d.Action;import com.badlogic.gdx.scenes.scene2d.Stage;import com.badlogic.gdx.scenes.scene2d.actions.Actions;import com.badlogic.gdx.scenes.scene2d.ui.Image;public class FirstGame implements ApplicationListener {private Stage stage;private Texture texture;@Overridepublic void create() {stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);texture = new Texture(Gdx.files.internal("star.png"));texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);    int maxWidth = Gdx.graphics.getWidth() - texture.getWidth();    int maxHeight = Gdx.graphics.getHeight() - texture.getHeight();        float duration = 4f;    int i;for(i = 0 ; i < 20 ; ++i){Image image = new Image(texture);image.setX(MathUtils.random(0,maxWidth));image.setY(MathUtils.random(0,maxHeight));//!!!!每一个Action都尽量要设置duration,否则Action在一瞬间就完成了Action moveAction = Actions.sequence(Actions.moveTo(MathUtils.random(0, maxWidth),MathUtils.random(0,maxHeight),duration/2) , Actions.moveBy(MathUtils.random(0, maxWidth),MathUtils.random(0,maxHeight) ,duration / 2));Action rotateAction = Actions.rotateTo(360,duration);Action repeatAction = Actions.repeat(10,Actions.sequence( Actions.fadeIn(duration / 20) , Actions.fadeOut(duration / 20)));Action parallelAction = Actions.parallel(moveAction,rotateAction,repeatAction);image.addAction(parallelAction);stage.addActor(image);}Gdx.input.setInputProcessor(stage);}@Overridepublic void dispose() {// TODO Auto-generated method stub}@Overridepublic void pause() {// TODO Auto-generated method stub}@Overridepublic void render() {Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);stage.act(Gdx.graphics.getDeltaTime());stage.draw();}@Overridepublic void resize(int arg0, int arg1) {// TODO Auto-generated method stub}@Overridepublic void resume() {// TODO Auto-generated method stub}}

本demo远吗下载链接:http://download.csdn.net/detail/caihongshijie6/6978303


1 0
原创粉丝点击