-
Notifications
You must be signed in to change notification settings - Fork 1
Rendering
miguel edited this page May 13, 2019
·
15 revisions
A Renderer
describes how a game object should get rendered:
public class MyRenderer implements GameObjectRenderer {
@Override
public void init() {
// is called when the renderer gets attached
}
@Override
public void render(GameObject object, Batch batch, float delta) {
// is called when the object should get rendered
}
}
brainGDX already comes with various predefined renderers which you can use to describe the render behavior for your entities:
- SpriteRenderer renders a defined sprite.
- AnimationRenderer renders a defined animation.
We need to register a renderer in order to display game objects on the screen:
// Retrieve the renderManager instance
RenderManager renderManager = context.getRenderManager();
// Registering a new renderer for game objects of type '1'
renderManager.register(1, new SpriteRenderer(Assets.Textures.PLAYER));
When running again you should see a red square on the screen.
To learn how to use the renderers, especially how to add actual game objects to your game learn more about game worlds. Also learn more about the game camera and how to track player movement.