# Class Scene

java.lang.Object
com.codename1.gaming.Scene

public class Scene extends Object

A z-ordered collection of sprites with an optional camera offset.

A `Scene` is the model a `SpriteRenderer` draws: it holds the sprites, keeps them sorted by `Sprite#getZOrder()` (higher draws on top, re-sorted only when the contents change) and applies a camera offset that scrolls the whole scene. `#update(double)` advances every sprite (driving `AnimatedSprite` playback).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Scene()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(Sprite s)`
  Adds a sprite to the scene.
  `void`
  `clear()`
  Removes all sprites.
  `Sprite`
  `get(int index)`
  `int`
  `getCameraX()`
  `int`
  `getCameraY()`
  `void`
  `markSortDirty()`
  Forces a re-sort on the next frame.
  `void`
  `remove(Sprite s)`
  Removes a sprite from the scene.
  `void`
  `setCamera(int x, int y)`
  Sets the camera offset subtracted from sprite positions while rendering.
  `int`
  `size()`
  `void`
  `update(double deltaSeconds)`
  Advances every sprite in the scene by calling `Sprite#onUpdate(double)`.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Scene

    public Scene()

- ## Method Details

  - ### add

    public void add(Sprite s)
    Adds a sprite to the scene.

  - ### remove

    public void remove(Sprite s)
    Removes a sprite from the scene.

  - ### clear

    public void clear()
    Removes all sprites.

  - ### size

    public int size()

  - ### get

    public Sprite get(int index)

  - ### update

    public void update(double deltaSeconds)
    Advances every sprite in the scene by calling `Sprite#onUpdate(double)`. Iterating by index tolerates a sprite removing itself during update.

  - ### markSortDirty

    public void markSortDirty()
    Forces a re-sort on the next frame. Call this after changing a sprite's z-order so the new ordering takes effect.

  - ### getCameraX

    public int getCameraX()

  - ### getCameraY

    public int getCameraY()

  - ### setCamera

    public void setCamera(int x, int y)
    Sets the camera offset subtracted from sprite positions while rendering.