CPScene

open class CPScene(id: String, dim: Option[CPDim], bgPx: CPPixel) extends CPGameObject with CPLifecycle

A scene is a container for scene objects. Scene objects from the scene are drawn on the screen on each frame.

Scene has an ID, optional dimension and one or more scene objects. Note that scene must always have at least one scene object. In CosPlay there is no hierarchy of scene objects in the scene - all scene objects form a simple flat structure inside of the scene. Just like with any other game objects, you can use tags to organize scenes and scene objects.

Creating A Scene

Scene has a strong encapsulation contract in relation to its scene objects: you can only add initial scene objects to the scene at the time of scene creation. Once scene is created, its constituent scene objects can only be manipulated via methods in CPSceneObjectContext class passed to scene objects on each frame update.

In CosPlay you create a new scene in one of two ways:

  • Instantiate CPScene class.
    When creating an instance of CPScene class you'll be using one of the constructors provided by CPScene class. Every constructor requires a set of initial scene objects to be supplied.
      val myScene = new CPScene("id", None, bgPx, spr1, spr2)
  • Extend CPScene class.
    When subclassing CPScene you need to use addObjects method available to the sub-classes to add initial scene objects.
       object MyScene extends CPScene("id", None, bgPx):
           addObjects(spr1, spr2)

Note that you can dynamically add and remove scene as well as scene objects via CPSceneObjectContext instance. See CPSceneObjectContext API for more details.

Scene Dimension

CosPlay scene can be adaptive or static in terms of its dimensions. When scene dimension is set it becomes unchangeable (static) for the lifecycle of the scene and its scene objects can rely on this fact. However, if scene dimension is set as None, it will adapt to the terminal dimension on each frame meaning that the scene's dimension and therefore its canvas on which all scene objects are rendered can change its size from frame to frame. Make sure that all scene objects in the adaptive scene take this into account in their rendering routines.

Value parameters:
bgPx

Background pixel of the scene. Background pixel is shown when none of the scene objects has drawn a pixel at that particular coordinate. Background pixel must have background color defined.

dim

Optional dimension of the scene. Note that if dimension is None then scene will adapt to the terminal dimension on each frame. That means that the scene's canvas on which all scene objects are rendered can change its size from frame to frame. In such case, make sure that all scene objects take this into account in their rendering routines.

id

ID of the scene.

See also:
Source:
CPScene.scala
class Object
trait Matchable
class Any

Value members

Constructors

def this(id: String, dim: Option[CPDim], bgPixel: CPPixel, objs: List[CPSceneObject])

Creates new scene with given parameters.

Creates new scene with given parameters.

Value parameters:
dim

Optional dimension of the scene. Note that if dimension is None then scene will adapt to the terminal dimension on each frame. That means that the scene's canvas on which all scene objects are rendered can change its size from frame to frame. Make sure that all scene objects take this into account in their rendering routines.

id

ID of the scene.

objs

Initial scene objects to add. Note that after the scene is created you can dynamically add and remove scene objects via CPSceneObjectContext instance. See CPSceneObjectContext API for more details.

Source:
CPScene.scala
def this(id: String, dim: Option[CPDim], bgPixel: CPPixel, objs: CPSceneObject*)

Creates new scene with given parameters.

Creates new scene with given parameters.

Value parameters:
dim

Optional dimension of the scene. Note that if dimension is None then scene will adapt to the terminal dimension on each frame. That means that the scene's canvas on which all scene objects are rendered can change its size from frame to frame. Make sure that all scene objects take this into account in their rendering routines.

id

ID of the scene.

objs

Initial scene objects to add. Note that after the scene is created you can dynamically add and remove scene objects via CPSceneObjectContext instance. See CPSceneObjectContext API for more details.

Source:
CPScene.scala

Concrete methods

inline def getBgColor: CPColor

Background color of the background pixel.

Background color of the background pixel.

Source:
CPScene.scala
inline def getBgPixel: CPPixel

Gets background pixel of this scene. Note that background pixel always has its background color defined.

Gets background pixel of this scene. Note that background pixel always has its background color defined.

Source:
CPScene.scala
inline def getCamera: CPCamera

Gets mutable camera panning descriptor associated with this scene. By default, the camera panning is not attached to any scene object. You need to configure the returning camera descriptor if you need camera tracking.

Gets mutable camera panning descriptor associated with this scene. By default, the camera panning is not attached to any scene object. You need to configure the returning camera descriptor if you need camera tracking.

Source:
CPScene.scala
inline def getDim: Option[CPDim]

Gets this scene dimension.

Gets this scene dimension.

Source:
CPScene.scala

Inherited methods

override def equals(obj: Any): Boolean
Definition Classes
Inherited from:
CPGameObject
Source:
CPGameObject.scala
def getId: String

Gets unique ID of this game object.

Gets unique ID of this game object.

Inherited from:
CPGameObject
Source:
CPGameObject.scala
final def getState: State

Gets current lifecycle state.

Gets current lifecycle state.

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def getTags: Set[String]

Gets optional set of organizational tags. Note that by default the set of tags is empty.

Gets optional set of organizational tags. Note that by default the set of tags is empty.

See also:
Inherited from:
CPGameObject
Source:
CPGameObject.scala
def onActivate(): Unit

Callback on lifecycle object activation. Default implementation is no-op.

Callback on lifecycle object activation. Default implementation is no-op.

See also:

CPLifecycle.State.LF_ACTIVE

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onDeactivate(): Unit

Callback on lifecycle object deactivation. Default implementation is no-op.

Callback on lifecycle object deactivation. Default implementation is no-op.

See also:

CPLifecycle.State.LF_INACTIVE

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onStart(): Unit

Callback on lifecycle object start. Default implementation is no-op.

Callback on lifecycle object start. Default implementation is no-op.

See also:

CPLifecycle.State.LF_STARTED

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onStop(): Unit

Callback on lifecycle object stop. Default implementation is no-op.

Callback on lifecycle object stop. Default implementation is no-op.

See also:

CPLifecycle.State.LF_STOPPED

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala