Class SpriteRenderer
- All Implemented Interfaces:
Renderer
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);
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a renderer with a fresh emptyScene.SpriteRenderer(Scene scene) Creates a renderer drawing the given scene. -
Method Summary
Modifier and TypeMethodDescriptionintgetScene()The scene this renderer draws; add and remove sprites here.voidonDispose(GraphicsDevice device) Invoked when the GPU context is being torn down (for example when the view is removed from the UI).voidonFrame(GraphicsDevice device) Invoked once per frame to render the scene.voidonInit(GraphicsDevice device) Invoked once after the GPU context and itsGraphicsDevicehave been created and are current.voidonResize(GraphicsDevice device, int width, int height) Invoked when the drawable surface size changes, including once after initialization.voidsetClearColor(int argb) The ARGB color the framebuffer is cleared to each frame.
-
Constructor Details
-
SpriteRenderer
public SpriteRenderer()Creates a renderer with a fresh emptyScene. -
SpriteRenderer
Creates a renderer drawing the given scene.
-
-
Method Details
-
getScene
The scene this renderer draws; add and remove sprites here. -
setClearColor
public void setClearColor(int argb) The ARGB color the framebuffer is cleared to each frame. -
getClearColor
public int getClearColor() -
onInit
Description copied from interface:RendererInvoked once after the GPU context and its
GraphicsDevicehave been created and are current. Allocate buffers, textures and materials here.Parameters
device: the graphics device bound to this view
-
onResize
Description copied from interface:RendererInvoked when the drawable surface size changes, including once after initialization. Reconfigure projection matrices and viewports here.
Parameters
-
device: the graphics device bound to this view -
width: the new drawable width in pixels -
height: the new drawable height in pixels
-
-
onFrame
Description copied from interface:RendererInvoked once per frame to render the scene. Issue draw calls against the supplied device.
Parameters
device: the graphics device bound to this view
-
onDispose
Description copied from interface:RendererInvoked when the GPU context is being torn down (for example when the view is removed from the UI). Release any resources that are not owned by the device. May be invoked with a null device when the context was lost.
Parameters
device: the graphics device bound to this view, or null if the context was already lost
-