CPCanvasSprite
Scene object tailor-made for canvas drawing.
Canvas sprite takes dimension of the current camera frame. That allows its CPSceneObject.render method, the only one method that needs to be implemented by the sub-type, to draw on entire camera frame of the terminal.
Note that by default this sprite sets its position and dimension equal to the entire camera frame. This may affect shaders attached to this sprite if they are configured to work with object vs. entire frame since this sprite will report its size as entire camera frame size. Shaders that work with this sprite should account for it.
Note, if overriding CPSceneObject.update method make sure to call super.update(...)
.
Sprites
CosPlay provides number of built-in sprites. A sprite is a scene objects, visible or off-screen, that is custom designed for a particular use case. Built-in sprites provide concrete implementations for the abstract methods in the base CPSceneObject class. Most non-trivial games will use combination of the built-in sprites and their own ones. Here's the list of the built-in sprites:
Value parameters
- id
-
Optional ID of this sprite.
- shaders
-
Optional list of shaders attached to this canvas sprite.
- tags
-
Optional set of organizational or grouping tags. By default, the empty set is used.
Attributes
- See also
-
CPSceneObjectContext.getCanvas to get current canvas you can draw on.
CPCanvas various API to draw on the canvas.
- Source
- CPCanvasSprite.scala
- Graph
-
- Supertypes
-
class CPSceneObjecttrait CPLifecycleclass CPGameObjectclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Gets current dimension (width and height) of this object.
Gets current dimension (width and height) of this object.
Attributes
- Definition Classes
- Source
- CPCanvasSprite.scala
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.
Attributes
- Definition Classes
- Source
- CPCanvasSprite.scala
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.
Attributes
- Definition Classes
- Source
- CPCanvasSprite.scala
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.
Attributes
- Definition Classes
- Source
- CPCanvasSprite.scala
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.
Attributes
- Definition Classes
- Source
- CPCanvasSprite.scala
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
- Definition Classes
- Source
- CPCanvasSprite.scala
Inherited methods
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 typeAny
,x.equals(x)
should returntrue
. - It is symmetric: for any instances
x
andy
of typeAny
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any instances
x
,y
, andz
of typeAny
ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
.
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
Gets optional collision shape or hit box for this sprite.
Gets optional collision shape or hit box for this sprite.
Attributes
- Returns
-
Optional collision shape,
None
if this sprite does not support collisions. - See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Gets current height of this object.
Gets current height of this object.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Gets unique ID of this game object.
Gets unique ID of this game object.
Attributes
- Inherited from:
- CPGameObject
- Source
- CPGameObject.scala
Gets rectangular shape of this sprite. It is basically a combination of its top-left corner XY-coordinate and sprite's dimension.
Gets rectangular shape of this sprite. It is basically a combination of its top-left corner XY-coordinate and sprite's dimension.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Gets current lifecycle state.
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
Gets current width of this object.
Gets current width of this object.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Shortcut method for hiding this object. Note that by default all scene objects are visible.
Shortcut method for hiding this object. Note that by default all scene objects are visible.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Checks the visibility flag.
Checks the visibility flag.
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.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
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
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
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
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
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.
Value parameters
- 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.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Sets visibility flag. Note that by default all scene objects are visible.
Sets visibility flag. Note that by default all scene objects are visible.
Value parameters
- vis
-
true
to make this object visible,false
otherwise.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Shortcut method for showing this object. Note that by default all scene objects are visible.
Shortcut method for showing this object. Note that by default all scene objects are visible.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala