Scene objects can be visible or invisible, have rectangular shape,
have XY-coordinates of its left-top corner and Z-index. On each game frame and for each scene object
the engine calls update method and, if object is visible and in frame, calls
render method followed by calling all of its shaders.
Scene is a container for for scene objects. Scene objects can be added or removed from
the scene dynamically via CPSceneObjectContext instance passed to update and render methods.
Note that all scenes should 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.
Generally, you would use one of many existing scene object subclasses like the various sprites provided out-of-the-box.
You can, however, just as easily subclass this class directly and provide the necessary implementation. At the
minimum you need to implement all abstract methods and at least one of either
render or update methods.
Here's a basic minimal scene object implementation that prints "Hello CosPlay!" text at (0,0)
coordinate in black color:
If scene object is invisible than only update method will be called
on each frame. If object is visible and in camera frame - method render will be called as well to
render itself. Note that shaders are called always, regardless of whether the object visible, in camera
frame or invisible.
Note that shader pass consists of two phases:
On the 1st phase shaders for all visible scene objects are processed
On the 2nd phase shaders for all invisible scene objects are processed.
This allows to minimize the interference between object shaders and full-screen shaders that are typically
attached to the off-screen sprite that is invisible. In other words, full-screen shaders will be execute
after all object shaders in a given scene.
Attributes
id
Optional ID of this scene object. By default, the random 6-character ID will be used.
tags
Optional set of organizational or grouping tags. By default, the empty set is used.
Gets current X-coordinate of this object within dimensions of its scene. Note that returned value
is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the
scene rendering will result in showing only portion or none of the object.
Gets current X-coordinate of this object within dimensions of its scene. Note that returned value
is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the
scene rendering will result in showing only portion or none of the object.
Gets current Y-coordinate of this object within dimensions of its scene. Note that returned value
is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the
scene rendering will result in showing only portion or none of the object.
Gets current Y-coordinate of this object within dimensions of its scene. Note that returned value
is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the
scene rendering will result in showing only portion or none of the object.
Gets Z-index or order to use in rendering of this object. A pixel with higher Z-index visually
overrides the overlapping pixel in the same XY-coordinate with equal or smaller Z-index.
Gets Z-index or order to use in rendering of this object. A pixel with higher Z-index visually
overrides the overlapping pixel in the same XY-coordinate with equal or smaller Z-index.
Gets the optional list of shaders attached to this scene object. By default, returns
an empty list. Note that shaders are called regardless of whether the object visible, in camera
frame or invisible.
Gets the optional list of shaders attached to this scene object. By default, returns
an empty list. Note that shaders are called regardless of whether the object visible, in camera
frame or invisible.
If object is invisible than only update method will be called
on each frame. If object is visible and in camera frame - method render will be called
as well to render itself. Note that shaders are called regardless of whether the object visible, in camera
frame or invisible.
Called to render this scene object. Only visible and in camera frame objects will receive this
callback. This callback is called on scene object
after all scene objects received update callback. Note that unlike update callbacks
and shaders that are called for all scene objects on each frame, this callback is only called for scene
objects that are visible and, at least partially, in camera frame.
Called to render this scene object. Only visible and in camera frame objects will receive this
callback. This callback is called on scene object
after all scene objects received update callback. Note that unlike update callbacks
and shaders that are called for all scene objects on each frame, this callback is only called for scene
objects that are visible and, at least partially, in camera frame.
Attributes
ctx
Frame context. This context provides bulk of functionality that a scene object
can do in a game, e.g. interact with other scene objects, check collisions, read input
events and manage input focus, add or remove scene objects, add new and switch between scenes, etc.
Called to update the internal state of this scene object. This callback is called each frame on every
object in the scene and it is called before any render callback. Note that all scene object will
receive this callback before first render callback.
Called to update the internal state of this scene object. This callback is called each frame on every
object in the scene and it is called before any render callback. Note that all scene object will
receive this callback before first render callback.
Attributes
ctx
Frame context. This context provides bulk of functionality that a scene object
can do in a game, e.g. interact with other scene objects, check collisions, read input
events and manage input focus, add or remove scene objects, add new and switch between scenes, etc.
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)).
Attributes
that
the object to compare against this object for equality.
Returns:
true if the receiver object is equivalent to the argument; false otherwise.