首页 > 其他 > 详细

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

时间:2014-03-02 11:51:19      阅读:465      评论:0      收藏:0      [点我收藏+]

直接贴本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;
	
	
	@Override
	public 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);
	}

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

	}

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

	}

	@Override
	public void render() {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		stage.act(Gdx.graphics.getDeltaTime());
		stage.draw();
		
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

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

	}

}

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


libgdx的基本使用——演员与演出,布布扣,bubuko.com

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

原文:http://blog.csdn.net/hjd_love_zzt/article/details/20214269

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!