public class SpriteRenderer
- Object
- SpriteRenderer
ImplementsRenderer
Draws a Scene of Sprites on the GPU, implementing the com.codename1.gpu
com.codename1.gpu.Renderer contract so it can be hosted in a
com.codename1.gpu.RenderView (which GameView does for you).
Each frame it sets up an orthographic camera that maps one world unit to one
pixel with the origin at the top left and y pointing down, then draws every
visible sprite as a textured quad: a shared unit quad mesh scaled/rotated/
translated by a per sprite model matrix, with a com.codename1.gpu.Material.Type#SPRITE
material (alpha blended, depth test off) whose texture is the sprite’s image and
whose color is the sprite’s tint. Images are uploaded to
com.codename1.gpu.Textures lazily and cached.
Use it directly for a custom host, or let GameView create and drive one:
SpriteRenderer r = new SpriteRenderer();
r.getScene().add(mySprite);
RenderView view = new RenderView(r).setContinuous(true);
form.add(BorderLayout.CENTER, view);
Constructors
public SpriteRenderer() | Creates a renderer with a fresh empty Scene. |
public SpriteRenderer(Scene scene) | Creates a renderer drawing the given scene. |
Methods
public Scene getScene() | The scene this renderer draws; add and remove sprites here. |
public GameCamera getCamera() | The camera this renderer draws through. |
public Light getLight() | The directional light used to shade lit 3D Models. |
public void addModel(Model model) | Adds a 3D model to be drawn (in perspective mode) alongside the sprites. |
public void removeModel(Model model) | Removes a previously added 3D model. |
public int getModelCount() | The number of 3D models in this renderer. |
public void setClearColor(int argb) | The ARGB color the framebuffer is cleared to each frame. |
public int getClearColor() | |
public void onInit(GraphicsDevice device) | Invoked once after the GPU context and its GraphicsDevice have been created and are current. |
public void onResize(GraphicsDevice device, int width, int height) | Invoked when the drawable surface size changes, including once after initialization. |
public void onFrame(GraphicsDevice device) | Invoked once per frame to render the scene. |
public void onDispose(GraphicsDevice device) | Invoked when the GPU context is being torn down (for example when the view is removed from the UI). |
Inherited methods
Constructor details
SpriteRenderer
public SpriteRenderer()Scene.SpriteRenderer
public SpriteRenderer(Scene scene)Method details
getScene
public Scene getScene()getCamera
public GameCamera getCamera()GameCamera#MODE_PERSPECTIVE to render the
sprites as billboards in a 3D world.getLight
public Light getLight()Models. Configure it with
com.codename1.gpu.Light#setDirection(float, float, float) etc.addModel
public void addModel(Model model)removeModel
public void removeModel(Model model)getModelCount
public int getModelCount()setClearColor
public void setClearColor(int argb)getClearColor
public int getClearColor()onInit
public void onInit(GraphicsDevice device)GraphicsDevice have been
created and are current. Allocate buffers, textures and materials here.Parameters
deviceGraphicsDevice- the graphics device bound to this view
onResize
public void onResize(GraphicsDevice device, int width, int height)Parameters
deviceGraphicsDevice- the graphics device bound to this view
widthint- the new drawable width in pixels
heightint- the new drawable height in pixels
onFrame
public void onFrame(GraphicsDevice device)Parameters
deviceGraphicsDevice- the graphics device bound to this view
onDispose
public void onDispose(GraphicsDevice device)Parameters
deviceGraphicsDevice- the graphics device bound to this view, or null if the context was already lost