public class Scene

  1. Object
  2. Scene

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).

Constructors

public Scene()

Methods

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

Inherited methods

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). Do not add or remove sprites from within onUpdate; defer that to the next frame.

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.