Giter Club home page Giter Club logo

gameroots's Introduction

Game Roots

Framework Components for Game Programming with Java

##Sorted Batch Rendering for LibGdx ###Motivation This is a spin-off from the development of the game Biodrone Battle. In the beginning, rendering was split up into multiple classes and as the code base grew, it was tedious to keep the right order for rendering layers of tiles and sprite components.

Furthermore, a lot of texture switches occurred. Whether that was a performance hit, was not analysed, but it was fixed easily after introducing sorted batch rendering. Taking the blend mode as sort criterium reduces the number of SpriteBatch flushes as well.

It is no longer necessary to provide an open SpriteBatch to each render class.

There are default implementations for rendering textures, particles and vertices. In case they don't meet your needs, just derive your own item classes from BatchRenderItem. The first sort criterium is always the layer (z-index) followed by individual criteria like texture handle or blend mode.

###Examples: Run BatchQueueLauncher to get a first impression.

Create a render queue for texture items:

		renderQueue = new BatchRenderQueue(MAX_LAYERS);
		renderQueue.addItemClass(TextureBatchItem.class, new Pool<BatchRenderItem>() {
			@Override
			protected TextureBatchItem newObject() {
				return new TextureBatchItem();
			}
		});

Queue a batch item:

			TextureBatchItem batchItem = renderQueue.obtainItem(TextureBatchItem.class);
			batchItem.setLayer(1);
			batchItem.setTextureRegion(SPRITE_REGION);
			batchItem.setLocation(123, 456);
			batchItem.setColor(Color.WHITE);

			renderQueue.queueItem(batchItem);

Draw all queued items:

private void render(BatchRenderQueue renderQueue, SpriteBatch batch) {
		batch.begin();
		long time = System.nanoTime();
		renderQueue.render(batch, time);
		batch.end();

###Modules and Packages: gameroots-frontend-libgdx:
de.voodoosoft.gameroots.frontend.gdx.view.render.batch

gameroots-frontend-examples:
de.voodoosoft.gameroots.examples.batch

gameroots's People

Contributors

voodoosoft avatar

Watchers

TheCocce avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.