Using LibGDX TextureRegion

After running into issues correctly loading managed Textures in my current LibGDX project when the Android app is backgrounded and foregrounded I refactored the project to use the TextureAtlas class and TextureRegions loaded from it. The transition was surprisingly smooth: the same amount of control with drawing is available on a TextureRegion as on a Sprite. Rotation around an origin and color tinting being my primary concerns. The main difference I found between the two approaches is that drawing happens through the SpriteBatch with a passed in TextureRegion rather than drawing through the Sprite with the SpriteBatch provied as a parameter. All of the transformations that I had been applying to the Sprite are now applied through the SpriteBatch draw method instead.

As an example of this different approach here is the code for my HealthBar class's render() function before and after the refactor. 

Before:

       public void render(SpriteBatch spriteBatch){

                backgroundSprite.setBounds(viewBounds.x, viewBounds.y, viewBounds.width, viewBounds.height);

                backgroundSprite.setOrigin(viewBounds.width/2f, viewBounds.height/2f);

                backgroundSprite.setRotation(rotation);

                backgroundSprite.draw(spriteBatch);

                barSprite.setBounds(currentHealthBounds.x, currentHealthBounds.y, currentHealthBounds.width, currentHealthBounds.height);

                barSprite.setRegionWidth((int)(barTexture.getWidth() * (currentHealth/maxHealth)));

                barSprite.setOrigin(viewBounds.width/2f-viewPadding, viewBounds.height/2f-viewPadding);

                barSprite.setRotation(rotation);

                barSprite.draw(spriteBatch);        

}

After:

        public void render(SpriteBatch spriteBatch){                float x = viewBounds.x;                float y = viewBounds.y;                float width = viewBounds.width;                float height = viewBounds.height;                float originX = viewBounds.width/2f;                float originY = viewBounds.height/2f;                                spriteBatch.draw(backgroundRegion, x, y, originX, originY, width, height, 1, 1, rotation);
                x = currentHealthBounds.x;                y = currentHealthBounds.y;                width = currentHealthBounds.width;                height = currentHealthBounds.height;                barRegion.setRegionWidth((int)(barRegion.getTexture().getWidth() * (currentHealth/maxHealth)));                originX = viewBounds.width/2f-viewPadding;                originY = viewBounds.height/2f-viewPadding;
                spriteBatch.draw(barRegion, x, y, originX, originY, width, height, 1, 1, rotation);        }

And it begins

So here is where a blog post will go, and I'm about to slap down some awesome. 

Game stuff to look out for

We've got two things we're working on that we expect to be released by the end of April. We're wrapping up a significant update to Cosmonuts. Then there's a new game prototpye for Android that we'll be publishing.

The update to Comonuts will include new nut types, new art, and a selection of levels for your nut gathering pleasure.

The new game prototype is a two player head to head game that plays on one device. The prototype will be released with very basic art, circles and lines. It is also being released as a two player only game, although planned future versions will have single player modes. We're putting this prototype out to get feedback from players and have plans already to make a more complete version.

GDC

Tavi and I were at GDC two weeks ago and we had a blast. We attended as CA's, which we both plan on doing for the forseeable future. Meeting lots of great people and hearing good advice always gets us really motivated. 

Inspiration always strikes during GDC, with so much exposure to new and different ideas. This year simply mishearing the name of another game inspired us to make a rediculous new game, which we'll blog about another time. We're really excited about it and can't wait to get a prototype together.

Hello World!