Book Image

Learning LibGDX Game Development- Second Edition

Book Image

Learning LibGDX Game Development- Second Edition

Overview of this book

Table of Contents (21 chapters)
Learning LibGDX Game Development Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Adding the screen transition capability


We need to use an interface that all our screen transitions will implement. This will allow us to easily add new transition effects later on a modular basis.

Create a new file for the ScreenTransition interface and add the following code:

package com.packtpub.libgdx.canyonbunny.screens.transitions;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public interface ScreenTransition {
  public float getDuration ();
  public void render (SpriteBatch batch, Texture currScreen,Texture nextScreen, float alpha);
}

The preceding interface allows us to query the duration of a transition effect and enables us to let it render its effect using two supplied textures that contain the images of the current and the next screens. In addition to this, the alpha value is used to describe the current state of progress of the transition effect that is to be rendered. Using an alpha value of 0.0, for example, will render the effect...