libgdxの基本的な使用--俳優と公演

2510 ワード

デモのコアコードを直接貼って、何か分からないことがあったら、前のブログを参考にしてください.
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