com.badlogic.gdx.graphics.g2d.SpriteBatch Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g2d.SpriteBatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From ud406 with MIT License 6 votes vote down vote up
public static void drawTextureRegion(SpriteBatch batch, TextureRegion region, float x, float y) {
    batch.draw(
            region.getTexture(),
            x,
            y,
            0,
            0,
            region.getRegionWidth(),
            region.getRegionHeight(),
            1,
            1,
            0,
            region.getRegionX(),
            region.getRegionY(),
            region.getRegionWidth(),
            region.getRegionHeight(),
            false,
            false);
}
 
Example #2
Source File: IciclesScreen.java    From ud405 with MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    hudViewport = new ScreenViewport();
    batch = new SpriteBatch();

    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    icicles = new Icicles(iciclesViewport, difficulty);

    Gdx.input.setInputProcessor(this);

    topScore = 0;
}
 
Example #3
Source File: CraftingScreen.java    From TerraLegion with MIT License 6 votes vote down vote up
@Override
public void render(SpriteBatch sb) {
	sb.setProjectionMatrix(camera.combined);
	sb.begin();
	sb.draw(bg, 0, 0);
	itemNameLabel.render(sb);
	itemInfoLabel.render(sb);
	cancelBtn.render(sb);
	craftingBtn.render(sb);
	invBtn.render(sb);
	if (selectedRecipe != null)
		craftBtn.render(sb);
	sb.end();

	stage.draw();
}
 
Example #4
Source File: WrathCardIconPatch.java    From jorbs-spire-mod with MIT License 6 votes vote down vote up
@SpirePostfixPatch
public static void Postfix(SingleCardViewPopup __this, SpriteBatch sb) {
    AbstractCard card = ReflectionUtils.getPrivateField(__this, SingleCardViewPopup.class, "card");
    int wrathCount = WrathField.wrathEffectCount.get(card);

    if (wrathCount == 0 || card.isLocked || !card.isSeen) {
        return;
    }

    RenderUtils.renderAtlasRegionCenteredAt(sb, wrathIconOverlayImg, WRATH_ICON_OFFSET_X, WRATH_ICON_OFFSET_Y);

    String text = Integer.toString(wrathCount);
    BitmapFont font = FontHelper.SCP_cardEnergyFont;
    float x = WRATH_TEXT_OFFSET_X;
    if (wrathCount > 9) x -= (20 * Settings.scale);
    FontHelper.renderFont(sb, font, text, x, WRATH_TEXT_OFFSET_Y, WRATH_TEXT_COLOR);
}
 
Example #5
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example #6
Source File: MainMenu.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public MainMenu (Invaders invaders) {
	super(invaders);

	spriteBatch = new SpriteBatch();
	background = new Texture(Gdx.files.internal("data/planet.jpg"));
	background.setFilter(TextureFilter.Linear, TextureFilter.Linear);

	logo = new Texture(Gdx.files.internal("data/title.png"));
	logo.setFilter(TextureFilter.Linear, TextureFilter.Linear);

	font = new BitmapFont(Gdx.files.internal("data/font16.fnt"), Gdx.files.internal("data/font16.png"), false);

	if (invaders.getController() != null) {
		invaders.getController().addListener(new ControllerAdapter() {
			@Override
			public boolean buttonUp(Controller controller, int buttonIndex) {
				controller.removeListener(this);
				isDone = true;
				return false;
			}
		});
	}
}
 
Example #7
Source File: NavMeshDebugDrawer.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
private void drawNavMeshIndices(SpriteBatch spriteBatch, Camera camera, BitmapFont font) {
	// TODO: Get rid of all the transform matrix setting
	if (spriteBatch.isDrawing()) {
		spriteBatch.end();
	}
	spriteBatch.begin();
	spriteBatch.setProjectionMatrix(camera.combined);
	for (int i = 0; i < navMesh.graph.getNodeCount(); i++) {
		Triangle t = navMesh.graph.getTriangleFromGraphIndex(i);
		if (triangleIsVisible(t)) {
			tmpMatrix.set(camera.view).inv().getRotation(tmpQuat);
			tmpMatrix.setToTranslation(t.centroid).rotate(tmpQuat);
			spriteBatch.setTransformMatrix(tmpMatrix);
			font.draw(spriteBatch, Integer.toString(t.triIndex), 0, 0);
		}
	}
	spriteBatch.end();
}
 
Example #8
Source File: AtlasRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) {

	float dx = getAlignDx(getWidth(), orgAlign);
	float dy = getAlignDy(getHeight(), orgAlign);

	if (tex == null) {
		RectangleRenderer.draw(batch, x + dx * scaleX, y + dy * scaleY, getWidth() * scaleX, getHeight() * scaleY,
				Color.RED);

		return;
	}

	x = x + tex.offsetX + dx;
	y = y + tex.offsetY + dy;

	if (tint != null)
		batch.setColor(tint);

	batch.draw(tex, x, y, -dx - tex.offsetX, -dy - tex.offsetY, tex.packedWidth, tex.packedHeight,
			flipX ? -scaleX : scaleX, scaleY, rotation);

	if (tint != null)
		batch.setColor(Color.WHITE);
}
 
Example #9
Source File: HelpScreen.java    From FruitCatcher with Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
       imageProvider = game.getImageProvider();
       backgroundImage = imageProvider.getBackgroundSpring();
       buttons = new Button [1];
       buttons[0] = new Button(imageProvider.getBack());        
       camera = new OrthographicCamera();
       camera.setToOrtho(false, imageProvider.getScreenWidth(), imageProvider.getScreenHeight());
       batch = new SpriteBatch();
       
       buttons[0].setPos(10, 10);
       
       font = new BitmapFont(Gdx.files.internal("fonts/poetsen.fnt"),
       			 		  Gdx.files.internal("fonts/poetsen.png"), false);
       
       startLine = 0;
       lineHeight = 30;
       lastLineIndex = game.getTextResources().getHelpLines().length - 1; 
       
       Gdx.input.setInputProcessor(this);
       Gdx.input.setCatchBackKey(true);        
}
 
Example #10
Source File: BGDrawer.java    From libGDX-Path-Editor with Apache License 2.0 6 votes vote down vote up
public void presentOverlayBG(int scrW, int scrH, int camX, int camY, int camW, int camH, SpriteBatch batch) {
	batch.begin();
	
	t.setSize(camW, (int)(camY + camH/2 - scrH));
	t.setPosition((int)(camX - camW/2), scrH);
	t.draw(batch, overlayBGAlpha);
	
	b.setSize(camW, (int)(-camY + camH/2));
	b.setPosition((int)(camX - camW/2), (int)(camY - camH/2));
   	b.draw(batch, overlayBGAlpha);
   	
   	l.setSize((int)(-camX + camW/2), scrH);
	l.setPosition((int)(camX - camW/2), 0);
   	l.draw(batch, overlayBGAlpha);
   	
	r.setSize((int)(camX + camW/2 - scrW), scrH);
	r.setPosition(scrW, 0);
   	r.draw(batch, overlayBGAlpha);
   	
   	batch.end();
}
 
Example #11
Source File: ClientPlayer.java    From killingspree with MIT License 5 votes vote down vote up
@Override
public void render(float delta, SpriteBatch batch) {
    walkDuration += delta;
    if (markForDispose) {
        dispose();
        return;
    }
    renderPlayer(batch);
    
}
 
Example #12
Source File: GameplayScreen.java    From ud406 with MIT License 5 votes vote down vote up
private void renderLevelEndOverlays(SpriteBatch batch) {
    if (level.gameOver) {

        if (levelEndOverlayStartTime == 0) {
            levelEndOverlayStartTime = TimeUtils.nanoTime();
            gameOverOverlay.init();
        }

        gameOverOverlay.render(batch);
        if (Utils.secondsSince(levelEndOverlayStartTime) > Constants.LEVEL_END_DURATION) {
            levelEndOverlayStartTime = 0;
            levelFailed();
        }
    } else if (level.victory) {
        if (levelEndOverlayStartTime == 0) {
            levelEndOverlayStartTime = TimeUtils.nanoTime();
            victoryOverlay.init();
        }

        victoryOverlay.render(batch);
        if (Utils.secondsSince(levelEndOverlayStartTime) > Constants.LEVEL_END_DURATION) {
            levelEndOverlayStartTime = 0;
            levelComplete();
        }

    }
}
 
Example #13
Source File: SpriteBatchUtils.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public static void drawString (SpriteBatch batch, String string, float x, float y, float w, float h) {
	String upstring = string.toUpperCase();
	for (int i = 0; i < string.length(); i++) {
		char ch = upstring.charAt(i);
		for (int ys = 0; ys < chars.length; ys++) {
			int xs = chars[ys].indexOf(ch);
			if (xs >= 0) {
				draw(batch, debugFont[xs][ys], x + i * w, y, w, h);
			}
		}
	}
}
 
Example #14
Source File: CommonKeywordIconsPatches.java    From StSLib with MIT License 5 votes vote down vote up
@SpireInsertPatch(locator = Locator.class)
public static void patch(AbstractCard c, SpriteBatch sb, @ByRef ArrayList<String>[] keywords) {
    if(CommonKeywordIconsField.useIcons.get(c)) {
        if (c.isInnate)
        {
            keywords[0].add(GameDictionary.INNATE.NAMES[0]);
        }
        if (c.isEthereal)
        {
            keywords[0].add(GameDictionary.ETHEREAL.NAMES[0]);
        }
        if (c.retain || c.selfRetain)
        {
            keywords[0].add(GameDictionary.RETAIN.NAMES[0]);
        }
        if (c.purgeOnUse)
        {
            keywords[0].add(purgeName);
        }
        if (c.exhaust || c.exhaustOnUseOnce)
        {
            keywords[0].add(GameDictionary.EXHAUST.NAMES[0]);
        }

        keywords[0] = keywords[0].stream().distinct().collect(Collectors.toCollection(ArrayList::new));
    }
}
 
Example #15
Source File: GameplayScreen.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void show() {
    AssetManager am = new AssetManager();
    Assets.instance.init(am);
    level = new Level();
    batch = new SpriteBatch();
    viewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);
}
 
Example #16
Source File: FluidSimulatorGeneric.java    From fluid-simulator-v2 with Apache License 2.0 5 votes vote down vote up
public FluidSimulatorGeneric(FluidSimulatorStarter fluidSimulatorStarter) {
		this.game = fluidSimulatorStarter;
		// LibGDX single batches cannot have a size more than 5460
		batch = new SpriteBatch(IS_DESKTOP ? 5460 : ANDROID_SIZE);
		font = new BitmapFont();
		camera = new OrthographicCamera(WORLD_WIDTH, WORLD_HEIGHT);
		camera.position.set(0, (WORLD_HEIGHT / 2) - 1, 0);
		immediateRenderer = new ImmediateModeRenderer20(SIZE*6, false, true, 0);
		irt = new Renderer20(SIZE*6, false, true, 1);
		irt2 = new ImmediateModeRenderer20(SIZE*11, false, true, 1);
		shapeRenderer = new ShapeRenderer(SIZE);
		renderer = new Box2DDebugRenderer(true, true, false, true, false, false);
		
		//3D
		camera3D = new PerspectiveCamera(67, WORLD_WIDTH, WORLD_HEIGHT);
		camera3D.position.set(0, 130f, 250f);
		camera3D.lookAt(0,150f,0);
		camera3D.near = 0.1f;
		camera3D.far = 500f;
		camera3D.update();
		ModelBuilder modelBuilder = new ModelBuilder();
//        model = modelBuilder.createSphere(5f, 5f, 5f, 4, 4, GL10.GL_TRIANGLES,
//                new Material(ColorAttribute.createDiffuse(Color.GREEN)),
//                Usage.Position | Usage.Normal);
        model = modelBuilder.createBox(5f, 5f, 5f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
        instance = new ModelInstance(model);
        modelBatch = new ModelBatch();
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
        environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 0, -0.8f, -0.2f));
        camController = new Camera3DController(camera3D);
        camController.setFluidSimulator(this);
		
		world = new World(new Vector2(0, -9.8f), false);
		world.setContactListener(this);
	}
 
Example #17
Source File: GameplayScreen.java    From ud406 with MIT License 5 votes vote down vote up
private void renderLevelEndOverlays(SpriteBatch batch) {
    if (level.gameOver) {

        if (levelEndOverlayStartTime == 0) {
            levelEndOverlayStartTime = TimeUtils.nanoTime();
            gameOverOverlay.init();
        }

        gameOverOverlay.render(batch);
        if (Utils.secondsSince(levelEndOverlayStartTime) > Constants.LEVEL_END_DURATION) {
            levelEndOverlayStartTime = 0;
            levelFailed();
        }
    } else if (level.victory) {
        if (levelEndOverlayStartTime == 0) {
            levelEndOverlayStartTime = TimeUtils.nanoTime();
            victoryOverlay.init();
        }

        victoryOverlay.render(batch);
        if (Utils.secondsSince(levelEndOverlayStartTime) > Constants.LEVEL_END_DURATION) {
            levelEndOverlayStartTime = 0;
            levelComplete();
        }

    }
}
 
Example #18
Source File: DeltaScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    Gdx.app.log(TAG, "show() called");
    batch = new SpriteBatch();
    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    font.getData().setScale(FONT_SCALE);
}
 
Example #19
Source File: GameplayScreen.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void show() {
    AssetManager am = new AssetManager();
    Assets.instance.init(am);

    batch = new SpriteBatch();
    gameplayViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    level = new Level(gameplayViewport);

    chaseCam = new ChaseCam(gameplayViewport.getCamera(), level.getGigaGal());
}
 
Example #20
Source File: SpriteBatchUtils.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public static void drawString (SpriteBatch batch, String string, float x, float y) {
	String upstring = string.toUpperCase();
	for (int i = 0; i < string.length(); i++) {
		char ch = upstring.charAt(i);
		for (int ys = 0; ys < chars.length; ys++) {
			int xs = chars[ys].indexOf(ch);
			if (xs >= 0) {
				draw(batch, debugFont[xs][ys], x + i * debugFontW, y);
			}
		}
	}
}
 
Example #21
Source File: DifficultyScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    renderer = new ShapeRenderer();
    batch = new SpriteBatch();

    viewport = new FitViewport(Constants.DIFFICULTY_WORLD_SIZE, Constants.DIFFICULTY_WORLD_SIZE);
    Gdx.input.setInputProcessor(this);

    font = new BitmapFont();
    font.getData().setScale(Constants.DIFFICULTY_LABEL_SCALE);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example #22
Source File: GameplayScreen.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void show() {
    AssetManager am = new AssetManager();
    Assets.instance.init(am);
    level = new Level();
    batch = new SpriteBatch();
    viewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);
    chaseCam = new ChaseCam(viewport.getCamera(), level.gigaGal);
}
 
Example #23
Source File: Magic.java    From super-snake with MIT License 5 votes vote down vote up
public Magic(float x, float y, String image_url) {
    super(x, y, 40);

    image = new Texture(Gdx.files.internal(image_url));
    batch = new SpriteBatch();

    srcWidth = image.getWidth();
    srcHeight = image.getHeight();
    float ratio = (float) srcHeight / (float) srcWidth;

    drawn_width = size;
    drawn_height = size * ratio;
    size = Math.max(size, size * ratio);
}
 
Example #24
Source File: Filtering.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void create() {
    batch = new SpriteBatch();
    viewport = new ScreenViewport();
    nearest = new Texture("standing-right.png");
    linear = new Texture("standing-right.png");
    linear.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example #25
Source File: Level.java    From ud406 with MIT License 5 votes vote down vote up
public void render(SpriteBatch batch, ShapeRenderer renderer) {

        renderer.begin(ShapeType.Filled);
        // TODO: Render all platforms in the platform array
        for (Platform platform : platforms) {
            platform.render(renderer);
        }
        renderer.end();

        batch.begin();
        gigaGal.render(batch);
        batch.end();
    }
 
Example #26
Source File: GameplayScreen.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void show() {
    AssetManager am = new AssetManager();
    Assets.instance.init(am);

    batch = new SpriteBatch();
    gameplayViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    level = new Level(gameplayViewport);

    chaseCam = new ChaseCam(gameplayViewport.getCamera(), level.getGigaGal());
}
 
Example #27
Source File: CampfireThirstEffect.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public void render(SpriteBatch sb) {
    sb.setColor(this.screenColor);
    sb.draw(ImageMaster.WHITE_SQUARE_IMG, 0.0F, 0.0F, (float) Settings.WIDTH, (float)Settings.HEIGHT);
    if (AbstractDungeon.screen == AbstractDungeon.CurrentScreen.GRID) {
        AbstractDungeon.gridSelectScreen.render(sb);
    }
}
 
Example #28
Source File: GameBatchRenderer.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public GameBatchRenderer (GL20 gl) {
	// setup a top-left origin
	// y-flip
	topLeftOrigin = new Matrix4();
	topLeftOrigin.setToOrtho(0, ScaleUtils.PlayWidth, ScaleUtils.PlayHeight, 0, 0, 10);
	identity = new Matrix4();

	// Issues may arise on Tegra2 (Asus Transformer) devices if the buffers'
	// count is higher than 10
	// batch = new SpriteBatch(1000, 8);
	batch = new SpriteBatch();
	begin = false;
	this.gl = gl;
}
 
Example #29
Source File: AccelerometerAxesScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    axisViewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);
    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);
    batch = new SpriteBatch();
    textViewport = new ScreenViewport();
    font = new BitmapFont();
    font.getData().setScale(TEXT_SCALE);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    maxAcceleration = 0;
    minAcceleration = Float.MAX_VALUE;

}
 
Example #30
Source File: BatchManager.java    From shapedrawer with MIT License 5 votes vote down vote up
public TextureRegion setTextureRegion(TextureRegion region) {
    TextureRegion oldRegion = this.r;
    this.r = region;
    float u = 0.5f * (r.getU() + r.getU2());
    float v = 0.5f * (r.getV() + r.getV2());
    for (int i = 0; i < verts.length; i+=VERTEX_SIZE) {
        verts[i + SpriteBatch.U1] = u;
        verts[i + SpriteBatch.V1] = v;
    }
    return oldRegion;
}