Example usage for com.badlogic.gdx.graphics.g2d SpriteBatch SpriteBatch

List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch SpriteBatch

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d SpriteBatch SpriteBatch.

Prototype

public SpriteBatch(int size) 

Source Link

Document

Constructs a SpriteBatch with one buffer and the default shader.

Usage

From source file:com.badlogic.gdx.tests.PremultiplyAlpha.java

private void gpuPremultiplyAlpha(String in, String out) {
    Texture texture = new Texture(Gdx.files.absolute(in));
    texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, texture.getWidth(), texture.getHeight(), false);
    buffer.getColorBufferTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    ShaderProgram shader = new ShaderProgram(VERTEX_SHADER, FRAG_SHADER);
    Gdx.app.log("Log", shader.getLog());
    SpriteBatch batch = new SpriteBatch(10);
    batch.getProjectionMatrix().setToOrtho2D(0, 0, texture.getWidth(), texture.getHeight());
    batch.disableBlending();//from  w ww  .j  a  va2 s . c  om
    batch.setShader(shader);

    //Premultiply
    buffer.begin();
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    batch.draw(texture, 0, 0);
    batch.end();
    Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight());
    buffer.end();

    //Save
    PixmapIO.writePNG(Gdx.files.absolute(out), pixmap);
    buffer.dispose();
    texture.dispose();
    pixmap.dispose();
    Gdx.app.exit();
}

From source file:com.cyphercove.lwptools.core.GaussianBlur.java

License:Apache License

/**
 *
 * @param initialAndMaxRadius The maximum blur radius this instance can support. The initial
 *                  radius is set to this value. The actual maximum blur radius will be rounded
 *                  up to the nearest even integer due to internal workings.
 * @param hasDepth//  w w w .j  a  v  a2s  .  c  o  m
 * @param keepInverseTarget Whether, when resizing, to create two target frame buffers so a screen
 *                          rotation can be done quickly without a pause.
 */
public GaussianBlur(float initialAndMaxRadius, boolean hasDepth, boolean keepInverseTarget,
        GaussianBlurShaderProvider shaderProvider) {
    if (initialAndMaxRadius < 0 || initialAndMaxRadius > MAX_RADIUS) {
        throw new GdxRuntimeException("Radius must be between 0 and " + MAX_RADIUS + " inclusive.");
    }

    this.hasDepth = hasDepth;
    this.keepInverseTarget = keepInverseTarget;
    this.useInverseTarget = false;
    spriteBatch = new SpriteBatch(1);

    this.maxRadius = (int) Math.ceil(initialAndMaxRadius);
    if (this.maxRadius % 2 != 0)
        this.maxRadius++; //round up to nearest even integer.
    offsets = new float[this.maxRadius / 2];
    weights = new float[this.maxRadius / 2];
    setRadius(initialAndMaxRadius);

    setTextureToSceneDepth(0.9999999f);//By default draw behind everything.

    this.shaderProvider = shaderProvider;

    if (initialAndMaxRadius > 0)
        blurPassShaderProgram = shaderProvider.obtainBlurPassShaderProgram(this.maxRadius);

}

From source file:com.hajnar.GravityShip.Screens.GameScreen.java

License:Apache License

public GameScreen(Game game) {
    Gdx.input.setInputProcessor(this);
    //      connectedController = Controllers.getControllers().first();
    //      if (connectedController != null)
    //      {//w ww  .j a v  a  2  s.  c om
    //         Gdx.app.log("Connected controller: ", connectedController + "");
    //         if (connectedController.getName().toLowerCase().contains("x-box") && connectedController.getName().toLowerCase().contains("360"))
    //            connectedController.addListener(this);
    //      }

    this.game = game;
    gameWorld = new GameWorld();
    gameWorld.loadWorld(GravityShip.prefs.getRecentWorld());
    this.batch = new SpriteBatch(300);
    this.staticCamera = new OrthographicCamera(Helper.FRUSTUM_WIDTH, Helper.FRUSTUM_HEIGHT);
    this.staticCamera.position.set(Helper.FRUSTUM_WIDTH / 2, Helper.FRUSTUM_HEIGHT / 2, 0);
    this.staticCamera.update();
    if (DEBUG_RENDER_ENABLED)
        this.worldRender = new GameWorldRenderGL2(gameWorld, batch, true);
    else
        this.worldRender = new GameWorldRenderGL2(gameWorld, batch, false);

    restartSprite = new Sprite(Assets.restartRegion);
    restartSprite.setPosition(Helper.FRUSTUM_WIDTH / 2 - restartSprite.getWidth() / 2,
            Helper.FRUSTUM_HEIGHT / 2 - restartSprite.getHeight() / 2);
    exitSprite = new Sprite(Assets.exitRegion);
    exitSprite.setPosition(Helper.FRUSTUM_WIDTH / 2 - exitSprite.getWidth() / 2,
            Helper.FRUSTUM_HEIGHT / 2 - exitSprite.getHeight() / 2 - 150);
    nextLevelSprite = new Sprite(Assets.nextLevelRegion);
    nextLevelSprite.setPosition(Helper.FRUSTUM_WIDTH / 2 - nextLevelSprite.getWidth() / 2,
            Helper.FRUSTUM_HEIGHT / 2 - nextLevelSprite.getHeight() / 2 + 150);
    resumeSprite = new Sprite(Assets.resumeRegion);
    resumeSprite.setPosition(Helper.FRUSTUM_WIDTH / 2 - resumeSprite.getWidth() / 2,
            Helper.FRUSTUM_HEIGHT / 2 - resumeSprite.getHeight() / 2 + 150);

    Assets.leftSprite.setPosition(Helper.FRUSTUM_WIDTH - 333, 20);
    Assets.rightSprite.setPosition(Helper.FRUSTUM_WIDTH - 190, 20);
    Assets.thrustSprite.setPosition(60, 20);

    Gdx.input.setCursorCatched(true);

    stringBuffer = new StringBuilder();

    levelDuration = 0;
    gameoverDuration = 0;
}

From source file:com.johnogel.astrobros.managers.GameManager.java

public GameManager(SuperManager mngr) {
    this.mngr = mngr;
    this.fps = 1 / 48f;
    max_count = 50;//from w  w  w. j a v  a2 s .  co  m
    alpha = 1;
    delta = .001f;

    game_objects = new Array();

    levels = new Array(6);
    controllers = new Array(10);

    texture_handler = mngr.getTextureHandler();

    batch = new SpriteBatch(100);

    shape_renderer = new ShapeRenderer();

    started = false;

    width = Gdx.graphics.getWidth() / 5;
    height = Gdx.graphics.getHeight() / 5;

    level = this.LEVEL_ONE;

    total_score = 0;

    lives = 3;
}

From source file:com.mknsri.drunktoss.Screen.java

License:Open Source License

public final void init(DrunkToss ebingeimi) {
    this.ebingeimi = ebingeimi;
    batch = new SpriteBatch(50);
    hudBatch = new SpriteBatch(10);
    batch.setProjectionMatrix(this.ebingeimi.camera.combined);
    hudBatch.setProjectionMatrix(this.ebingeimi.hudCamera.combined);
    font = new BitmapFont();
    layout = new GlyphLayout(font, "");
}

From source file:com.ore.infinium.systems.TileRenderer.java

License:Open Source License

public TileRenderer(OrthographicCamera camera, World world, float interval) {
    super(interval);
    elapsed = interval;/*from   ww w .j  a  v  a2  s .c om*/

    m_camera = camera;
    m_world = world;
    m_batch = new SpriteBatch(5000);

    m_blockAtlas = new TextureAtlas(Gdx.files.internal("packed/blocks.atlas"));
    m_tilesAtlas = new TextureAtlas(Gdx.files.internal("packed/tiles.atlas"));
    for (TextureRegion region : m_tilesAtlas.getRegions()) {
        region.flip(false, true);
    }

    //dirt 16 and beyond are transition things.
    final int dirtMax = 25;
    dirtBlockMeshes = new IntMap<>(dirtMax);
    for (int i = 0; i <= dirtMax; ++i) {
        String formatted = String.format("dirt-%02d", i);
        dirtBlockMeshes.put(i, formatted);
    }

    //18+ are transition helpers
    final int grassMax = 20;
    grassBlockMeshes = new IntMap<>(grassMax);
    for (int i = 0; i <= grassMax; ++i) {
        String formatted = String.format("grass-%02d", i);
        grassBlockMeshes.put(i, formatted);
    }

    final int stoneMax = 30;
    stoneBlockMeshes = new IntMap<>(stoneMax);
    for (int i = 0; i <= stoneMax; ++i) {
        String formatted = String.format("stone-%02d", i);
        stoneBlockMeshes.put(i, formatted);
    }
}

From source file:com.turbogerm.helljump.game.GameArea.java

License:Open Source License

public GameArea(CameraData cameraData, AssetManager assetManager, BitmapFont itemFont) {

    mAssetManager = assetManager;/* w  w w. ja v  a2  s . c o m*/
    mBatch = new SpriteBatch(SPRITE_BATCH_SIZE);
    mDebugData = new DebugData();
    mItemFont = itemFont;
    mCameraData = cameraData;

    mCharacter = new GameCharacter(mCameraData, mAssetManager);
    mActiveAreaObjects = new GameActiveAreaObjects();

    mGameBackground = new GameBackground(GameAreaUtils.getBackgroundColorSpectrum(), true, mCameraData,
            assetManager);
    mEndBackgroundScene = new EndBackgroundScene(cameraData, assetManager);
    mGameForeground = new GameForeground(mCameraData, mAssetManager);

    reset();
}

From source file:kyle.game.besiege.MapScreen.java

License:Open Source License

public MapScreen() {
    camera = new OrthographicCamera(BesiegeMain.WIDTH, BesiegeMain.HEIGHT);

    SpriteBatch kingdomBatch = new SpriteBatch(5460); // optimizes swapBuffers
    kingdomStage = new Stage();
    kingdomStage = new Stage(0, 0, false, kingdomBatch);
    kingdomStage.setCamera(camera);// w  w  w . j  ava 2  s.  c o  m
    uiStage = new Stage();
    uiStage.addListener(new InputListener());
    sidePanel = new SidePanel(this);

    kingdom = new Kingdom(this);
    sidePanel.setKingdom(kingdom);
    //      fog = new Fog(this);

    mapControllerAndroid = new MapControllerAndroid(camera, this);
    mapControllerDesktop = new MapControllerDesktop(camera, this);
    kingdomStage.addActor(kingdom);
    //      kingdomStage.addActor(fog); // test to see if this is slowing things down
    mousePos = new Vector2(0, 0);
    rotation = 0;
    speedFactor = 1;

    // if commented out, no more leaks!
    // leak is in SidePanel.act
    uiStage.addActor(sidePanel);
    mouseOverPanel = false;
    keydown = 0;

    character = new Character(this, "Kyle");
    kingdom.addPlayer();
    sidePanel.initializePanels();

    shouldCenter = false;
    shouldFastForward = false;
    shouldLetRun = false;

    fogOn = false;
    losOn = true;
    fogToggle = false;
    losToggle = true;

    startLog();
}