-
Notifications
You must be signed in to change notification settings - Fork 0
Reflection
Available since LibGDX version 0.9.9.
In order to utilize reflection in a cross-platform way, LibGDX provides a small wrapper around Java's reflection api. The wrapper consists mainly of two classes containing the static methods you will use to perform reflection operations:
-
ArrayReflection
- encapsulates access to java.lang.reflect.Array -
ClassReflection
- encapsulates access to java.lang.Class
Other classes included in the wrapper provide access to Constructors, Fields, and Methods. These classes (for the most part) mirror their java.lang.reflect equivalent. and can be used in the same way.
In general, you will use the reflection wrapper the same way you would use Java's reflection API, except you'd route the calls through the appropriate wrapper class instead of calling the methods directly.
Examples:
Operation | Java | Wrapper |
---|---|---|
Create a new instance of an array of a specified component type | Array.newInstance(clazz, size) |
ArrayReflection.newInstance(clazz, size) |
Obtain the Class object for a class by name | Class.forName("java.lang.Object") |
ClassReflection.forName("java.lang.Object") |
Create a new instance of a class | clazz.newInstance() |
ClassReflection.newInstance(clazz) |
Get the fields of a class | clazz.getFields() |
ClassReflection.getFields(clazz) |
Because GWT does not allow for reflection in the same way as Java, extra steps are required to make reflection information available to your GWT application. In short, you must specify which classes you plan to use with reflection. When compiling the HTML project, LibGDX takes that information and generates a reflection cache containing information about and providing access to the constructors, fields and methods of the specified classes. LibGDX then uses this reflection cache to implement the reflection api.
Classes are specified by including a special configuration property in your GWT module definition (*
.gwt.xml).
To include a single class:
<extend-configuration-property name="gdx.reflect.include" value="com.me.reflected.ReflectedClass" />
To include an entire package:
<extend-configuration-property name="gdx.reflect.include" value="com.me.reflected" />
You can also exclude classes of packages (for example when you include a package, but you don't want all classes or subpackages in that package):
<extend-configuration-property name="gdx.reflect.exclude" value="com.me.reflected.NotReflectedClass" />
Notes
- You must specify the fully qualified name of the class or package.
- You must specify each class or package in its own
extend-configuration-property
element. - Any classes referenced by those classes you include will automatically be included, so you need only include your own classes.
-
Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Gradle Project Setup, Running, Debugging and Packaging
- Project Setup, Running & Debugging
- Third Party Services
- Working from Source
- Using libgdx with other JVM languages
- The Application Framework
- A Simple Game
- File Handling
- Networking
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Take a Screenshot
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprite * 2D Animation * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * Viewports * NinePatches * Bitmap Fonts * Distance field fonts * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Skin
- 3D Graphics * Quick Start * Models * Material and environment * 3D animations and skinning * Importing Blender models in LibGDX * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Physics
- Tools
- Extensions
- Deploying your Application
- Building Libgdx ??
- Known Issues
- Articles
- Deprecated (May be outdated)