CPScene

org.cosplay.CPScene
open class CPScene(id: String, dim: Option[CPDim], bgPx: CPPixel) extends CPGameObject, 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.

Attributes

See also
Source
CPScene.scala
Graph
Supertypes
trait CPLifecycle
class CPGameObject
class Object
trait Matchable
class Any
Known subtypes

Members list

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.

Attributes

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.

Attributes

Source
CPScene.scala

Concrete methods

inline def getBgColor: CPColor

Background color of the background pixel.

Background color of the background pixel.

Attributes

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.

Attributes

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.

Attributes

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

Gets this scene dimension.

Gets this scene dimension.

Attributes

Source
CPScene.scala

Inherited methods

override def equals(obj: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
CPGameObject -> Any
Inherited from:
CPGameObject
Source
CPGameObject.scala
def getId: String

Gets unique ID of this game object.

Gets unique ID of this game object.

Attributes

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

Gets current lifecycle state.

Gets current lifecycle state.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

See also

CPLifecycle.State.LF_STOPPED

Inherited from:
CPLifecycle
Source
CPLifecycle.scala