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

直接贴本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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

帅气的东哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值