2014年10月21日 10:46
package com.mygdx.game.desktop;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mygdx.game.MyGdxGameButton;
public class DesktopLauncher extends ApplicationAdapter {
private static DesktopLauncher application;
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = MyGdxGameButton.TITLE + "V" + MyGdxGameButton.VERSION;
//ここで設定したいけど、まだMyGdxGameButtonが生成されていないので、
//SplashのShowで行う。
// config.vSyncEnabled = Settings.vSync();
config.vSyncEnabled = true;
config.useGL30 = false;
config.width = 1136; // xperia ray 854
config.height = 640; // xperia ray 480
//フルスクリーン
// config.fullscreen = true;
new LwjglApplication(new MyGdxGameButton(), config); // ①
}
}
package com.mygdx.game;
import com.badlogic.gdx.Game;
import com.mygdx.game.sceens.Splash;
public class MyGdxGameButton extends Game{
public static final String TITLE = "OH MY GOD!!!";
public static final String VERSION = "0.0.0.0";
@Override
public void create() {
setScreen(new Splash()); // ①
}
@Override
public void dispose() {
super.dispose();
}
@Override
public void render() {
super.render();
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
}
@Override
public void pause() {
super.pause();
}
@Override
public void resume() {
super.resume();
}
}
package com.mygdx.game.sceens;
import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenManager;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.mygdx.game.tween.SpriteAccessor;
public class Splash implements Screen{
private SpriteBatch batch;
private Sprite splash;
private TweenManager tweenManager;
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
tweenManager.update(delta); // ④
batch.begin(); // ⑤
splash.draw(batch);
batch.end();
// dispose();
}
@Override
public void resize(int width, int height) {
splash.setSize(width, height);
}
@Override
public void show() {
//Mainで設定したいけど、
Gdx.graphics.setVSync(Settings.vSync());
batch = new SpriteBatch();
tweenManager = new TweenManager();
Tween.registerAccessor(Sprite.class, new SpriteAccessor()); // ①
Texture splashTexture = new Texture(Gdx.files.internal("img/sprash.png")); // ②
splash = new Sprite(splashTexture);
splash.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Tween.set(splash, SpriteAccessor.ALPHA).target(0).start(tweenManager);
//フェードイン、フェードアウトした後のコールバックを書くよ!
Tween.to(splash, SpriteAccessor.ALPHA, 2).target(1).repeatYoyo(1, 0.5f).setCallback(new TweenCallback(){
@Override
public void onEvent(int type, BaseTween source) {
// ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu()); // ③
exit(0);
}
}).start(tweenManager);
// tweenManager.update(Gdx.graphics.getDeltaTime());
tweenManager.update(Float.MIN_VALUE);
}
@Override
public void hide() {
dispose();
}
@Override
public void pause() {
// TODO 自動生成されたメソッド・スタブ
}
@Override
public void resume() {
// TODO 自動生成されたメソッド・スタブ
}
@Override
public void dispose() {
batch.dispose();
splash.getTexture().dispose();
}
}
package com.mygdx.game.tween;
import aurelienribon.tweenengine.TweenAccessor;
import com.badlogic.gdx.graphics.g2d.Sprite;
public class SpriteAccessor implements TweenAccessor {
public static final int ALPHA = 0;
@Override
public int getValues(Sprite target, int tweenType, float[] returnValues) {
switch(tweenType){
case ALPHA:
returnValues[0] = target.getColor().a;
return 1;
default:
assert false;
return -1;
}
}
@Override
public void setValues(Sprite target, int tweenType, float[] newValues) {
switch(tweenType){
case ALPHA:
target.setColor(target.getColor().r, target.getColor().g,target.getColor().b, newValues[0]);
default:
assert false;
}
}
}