CPScene
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
- Known subtypes
-
class CPFadeShimmerLogoSceneclass CPSlideShimmerLogoScene