CPVideoSprite

org.cosplay.CPVideoSprite
class CPVideoSprite(id: String, vid: CPVideo, x: Int, y: Int, z: Int, fps: Int, autoPlay: Boolean, loop: Boolean, collidable: Boolean, shaders: Seq[CPShader]) extends CPSceneObject

Scene object tailor-made for rendering videos.

Video support consists of three key components:

Video is defined as a sequence of same-sized frames where each frame is an image. CPVideoSprite provides rendering of that video while CPVideoSpriteListener allows the video playback to synchronize with other action in the game like sound or animation. Note that video sprite does not provide any playback controls out of the box.

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:

Here's some useful links for ASCII video in general:

Attributes

autoPlay

Whether to autoplay the video.

collidable

Whether or not this sprite has a collision shape. Default is false.

fps

Frame-per-second to use in rendering the video.

id

Optional ID of the sprite.

loop

Whether or not to loop the playback.

shaders

Optional sequence of shaders for this sprite. Default value is an empty sequence.

vid

Video to render.

x

Initial X-coordinate of the sprite.

y

Initial Y-coordinate of the sprite.

z

Z-index at which to render the image.

See also:

CPSceneObjectContext.getCanvas to get current canvas you can draw on.

CPCanvas various API to draw on the canvas.

Example:

See CPVideoExample class for the example of using video support.

Source:
CPVideoSprite.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Concrete methods

Adds video playback listener.

Adds video playback listener.

Attributes

lst

Listener to add.

Source:
CPVideoSprite.scala
override def getCollisionRect: Option[CPRect]

Gets optional collision shape or hit box for this sprite.

Gets optional collision shape or hit box for this sprite.

Attributes

Definition Classes
Source:
CPVideoSprite.scala
override def getDim: CPDim

Gets current dimension (width and height) of this object.

Gets current dimension (width and height) of this object.

Attributes

Definition Classes
Source:
CPVideoSprite.scala
def getFrameIndex: Long

Gets current video frame index.

Gets current video frame index.

Attributes

Source:
CPVideoSprite.scala
override def getRect: CPRect

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

Definition Classes
Source:
CPVideoSprite.scala
override def getShaders: Seq[CPShader]

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:
CPVideoSprite.scala
override def getX: Int

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:
CPVideoSprite.scala
override def getY: Int

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:
CPVideoSprite.scala
override def getZ: Int

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:
CPVideoSprite.scala
def isPlaying: Boolean

Tests whether or not playback is playing.

Tests whether or not playback is playing.

Attributes

Source:
CPVideoSprite.scala

Removes video playback listener.

Removes video playback listener.

Attributes

lst

Listener to remove.

Source:
CPVideoSprite.scala
override def render(ctx: CPSceneObjectContext): Unit

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

Definition Classes
Source:
CPVideoSprite.scala
def rewind(): Unit

Rewinds the playback back to the beginning.

Rewinds the playback back to the beginning.

Attributes

Source:
CPVideoSprite.scala
def seek(idx: Int): Unit

Seeks playback to given vide frame index.

Seeks playback to given vide frame index.

Attributes

idx

Video frame index to seek.

Source:
CPVideoSprite.scala
def startPlayback(): Unit

Starts playback.

Starts playback.

Attributes

Source:
CPVideoSprite.scala
def stopPlayback(): Unit

Stops playback.

Stops playback.

Attributes

Source:
CPVideoSprite.scala
def toggle(): Unit

Toggles playback.

Toggles playback.

Attributes

Source:
CPVideoSprite.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)).

Attributes

that

the object to compare against this object for equality.

Returns:

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

Definition Classes
Inherited from:
CPGameObject
Source:
CPGameObject.scala
inline def getHeight: Int

Gets current height of this object.

Gets current height of this object.

Attributes

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.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
inline def getWidth: Int

Gets current width of this object.

Gets current width of this object.

Attributes

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def hide(): Unit

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
def isVisible: Boolean

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
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
def setVisible(vis: Boolean): Unit

Sets visibility flag. Note that by default all scene objects are visible.

Sets visibility flag. Note that by default all scene objects are visible.

Attributes

vis

true to make this object visible, false otherwise.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def show(): Unit

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

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.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala