CPSceneObjectContext

org.cosplay.CPSceneObjectContext

Scene object context during frame update.

This type is main access point to the most of CosPlay functionality for the scene objects comprising the gameplay. On each game frame update all scene objects from the current scene receive CPSceneObject.update call and optional CPSceneObject.render call both of which receive the instance of this type. Also, the shaders attached to that scene objects, if any, receive the callback with the instance of this type.

Scene object context functionality can be grouped into:

Attributes

See also:
Source:
CPSceneObjectContext.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Abstract methods

def acquireFocus(id: String): Unit

Makes the scene object with given ID the owner of the input keyboard focus.

Makes the scene object with given ID the owner of the input keyboard focus.

Attributes

id

ID of the scene object.

See also:
Source:
CPSceneObjectContext.scala
def addObject(obj: CPSceneObject): Unit

Adds given scene object to the scene after this update cycle. Change will be visible only on the next frame update.

Adds given scene object to the scene after this update cycle. Change will be visible only on the next frame update.

Attributes

obj

Scene object to add.

Source:
CPSceneObjectContext.scala
def addScene(newSc: CPScene, switchTo: Boolean, delCur: Boolean): Unit

Adds new scene. Change will be visible only on the next frame update.

Adds new scene. Change will be visible only on the next frame update.

Attributes

delCur

If immediately switching to the new scene, whether or not to remove the current scene.

newSc

A scene to add.

switchTo

Whether or not to immediately switch to this scene right after this frame update cycle.

Source:
CPSceneObjectContext.scala
def collisions(zs: Int*): Seq[CPSceneObject]

Gets the sequence of scene objects this object is colliding with. If no collisions are detected - this method returns an empty list.

Gets the sequence of scene objects this object is colliding with. If no collisions are detected - this method returns an empty list.

NOTE: for a scene object to participate in the collision it must provide its collision shape. If scene object does not provide the collision shape (the default behavior) it will be ignored when checking for collision by other scene objects, and an exception will be thrown if such object initiates the check for the collision with itself.

Attributes

zs

Zero or more Z-indexes to check collision at. If none provided, scene objects at all Z-indexes with be checked.

See also:
Source:
CPSceneObjectContext.scala
def collisions(rect: CPRect, zs: Int*): Seq[CPSceneObject]

Gets the sequence of scene objects colliding with given rectangular. If no collisions are detected - this method returns an empty list.

Gets the sequence of scene objects colliding with given rectangular. If no collisions are detected - this method returns an empty list.

NOTE: for a scene object to participate in the collision it must provide its collision shape. If scene object does not provide the collision shape (the default behavior) it will be ignored when checking for collision by other scene objects, and an exception will be thrown if such object initiates the check for the collision with itself.

Attributes

zs

Zero or more Z-indexes to check collision at. If none provided, scene objects at all Z-indexes with be checked.

See also:
Source:
CPSceneObjectContext.scala
def collisions(x: Int, y: Int, zs: Int*): Seq[CPSceneObject]

Gets the sequence of scene objects colliding with given coordinate. If no collisions are detected - this method returns an empty list.

Gets the sequence of scene objects colliding with given coordinate. If no collisions are detected - this method returns an empty list.

NOTE: for a scene object to participate in the collision it must provide its collision shape. If scene object does not provide the collision shape (the default behavior) it will be ignored when checking for collision by other scene objects, and an exception will be thrown if such object initiates the check for the collision with itself.

Attributes

zs

Zero or more Z-indexes to check collision at. If none provided, scene objects at all Z-indexes with be checked.

See also:
Source:
CPSceneObjectContext.scala
def countObjectsForTags(tags: String*): Int

Gets number of scene objects with given tags. All tags must be present in the scene object to be returned as part of the result sequence.

Gets number of scene objects with given tags. All tags must be present in the scene object to be returned as part of the result sequence.

Attributes

tags

One or more tags to filter by.

Source:
CPSceneObjectContext.scala
def deleteObject(id: String): Unit

Deletes given scene object after this update cycle. Change will be visible only on the next frame update. Note that focus owner will be released if held by the deleted object.

Deletes given scene object after this update cycle. Change will be visible only on the next frame update. Note that focus owner will be released if held by the deleted object.

Attributes

id

ID of the scene object to delete after this update cycle.

Source:
CPSceneObjectContext.scala
def deleteScene(id: String): Unit

Deletes given scene. Note that you can't delete current scene.

Deletes given scene. Note that you can't delete current scene.

Attributes

id

ID of the scene to delete. Cannot be the current scene.

Source:
CPSceneObjectContext.scala
def exitGame(): Unit

Exits the CPEngine.startGame method.

Exits the CPEngine.startGame method.

Attributes

Source:
CPSceneObjectContext.scala

Gets camera control descriptor for the current scene.

Gets camera control descriptor for the current scene.

Attributes

Source:
CPSceneObjectContext.scala

Gets current camera frame. Camera frame is always a sub-region of the scene. In most cases, it is a smaller value between scene dimension and terminal dimension.

Gets current camera frame. Camera frame is always a sub-region of the scene. In most cases, it is a smaller value between scene dimension and terminal dimension.

Attributes

Source:
CPSceneObjectContext.scala

The canvas instance on which this scene object renders its content. In most cases, you should only render in CPSceneObject.render call.

The canvas instance on which this scene object renders its content. In most cases, you should only render in CPSceneObject.render call.

Attributes

Source:
CPSceneObjectContext.scala
def getFocusOwner: Option[String]

Gets ID of the scene object owning the input focus, if any. If None - no object is owning the input focus and all objects will get input events.

Gets ID of the scene object owning the input focus, if any. If None - no object is owning the input focus and all objects will get input events.

Attributes

See also:
Source:
CPSceneObjectContext.scala
def getId: String

ID of the scene object that is being processed.

ID of the scene object that is being processed.

Attributes

Source:
CPSceneObjectContext.scala

Gets current frame's keyboard event.

Gets current frame's keyboard event.

Attributes

Source:
CPSceneObjectContext.scala
def getObject(id: String): Option[CPSceneObject]

Gets scene object with given ID.

Gets scene object with given ID.

Attributes

id

ID of the scene object to get.

Source:
CPSceneObjectContext.scala
def getObjectsForTags(tags: Seq[String]): Seq[CPSceneObject]

Gets sequence of scene objects with given tags. All tags must be present in the scene object to be returned as part of the result sequence.

Gets sequence of scene objects with given tags. All tags must be present in the scene object to be returned as part of the result sequence.

Attributes

tags

One or more tags to filter by.

Source:
CPSceneObjectContext.scala

Gets the current owner of input keyboard focus.

Gets the current owner of input keyboard focus.

Attributes

Source:
CPSceneObjectContext.scala

Gets rendering statistics, if available.

Gets rendering statistics, if available.

Attributes

See also:
Source:
CPSceneObjectContext.scala
def grabObject(id: String): CPSceneObject

Gets scene object with given ID. Throws CPException exception if object with given ID not found.

Gets scene object with given ID. Throws CPException exception if object with given ID not found.

Attributes

id

ID of the scene object to get.

Throws:
CPException

Thrown if object with given ID not found.

Source:
CPSceneObjectContext.scala
def isVisible: Boolean

Checks whether the object this context is attached to is visible.

Checks whether the object this context is attached to is visible.

Attributes

Source:
CPSceneObjectContext.scala
def receiveMessage(): Seq[AnyRef]

Gets direct messages send to this scene object, if any. Returns an empty sequence if no messages pending delivery. Note that sent messages are stored until they are retrieved or the scene is changed.

Gets direct messages send to this scene object, if any. Returns an empty sequence if no messages pending delivery. Note that sent messages are stored until they are retrieved or the scene is changed.

Attributes

See also:
Source:
CPSceneObjectContext.scala
def releaseFocus(id: String): Unit

Releases the input focus if it is help by the object with given ID. No-op in all other cases.

Releases the input focus if it is help by the object with given ID. No-op in all other cases.

Attributes

id

ID of the scene object.

See also:
Source:
CPSceneObjectContext.scala
def releaseMyFocus(): Unit

Releases the input keyboard focus if it is held by the current scene object. No-op in all other cases.

Releases the input keyboard focus if it is held by the current scene object. No-op in all other cases.

Attributes

See also:
Source:
CPSceneObjectContext.scala
def runLater(delayMs: Long, f: CPSceneObjectContext => Unit): Unit

Schedules given function to run at least delayMs milliseconds later or upon scene switch. Given function will only run if its timer elapses during the current scene or scene changes. Note that given function will run at the minimum the next frame and never in the current frame (even if delayMs is set to 1ms, for example).

Schedules given function to run at least delayMs milliseconds later or upon scene switch. Given function will only run if its timer elapses during the current scene or scene changes. Note that given function will run at the minimum the next frame and never in the current frame (even if delayMs is set to 1ms, for example).

Attributes

delayMs

Minimum number of milliseconds before given function will run in the current scene. Note that the actual delay can be bigger but never smaller than this parameter unless scene changes.

f

A function to run later in the current scene.

Source:
CPSceneObjectContext.scala
def runNextFrame(f: CPSceneObjectContext => Unit): Unit

Schedules given function to run at the next frame update. More specifically, this function will run before any of the scene objects updates on the next frame. Given function will only run if the next frame belongs to the same scene. In other words, at scene switch all currently pending functions will be discarded.

Schedules given function to run at the next frame update. More specifically, this function will run before any of the scene objects updates on the next frame. Given function will only run if the next frame belongs to the same scene. In other words, at scene switch all currently pending functions will be discarded.

Attributes

f

A function to run in the next frame update of the current scene.

Source:
CPSceneObjectContext.scala
def sendMessage(id: String, msgs: AnyRef*): Unit

Sends direct message(s) to the scene object with given ID. Scene object must belong to the current scene, i.e. one cannot send a message to the scene objects from another scene. To exchange data between scenes you should use game cache. Note that messages will be available to recipient scene objects starting with the next frame. Messages will be stored until they are retrieved or the scene is changed.

Sends direct message(s) to the scene object with given ID. Scene object must belong to the current scene, i.e. one cannot send a message to the scene objects from another scene. To exchange data between scenes you should use game cache. Note that messages will be available to recipient scene objects starting with the next frame. Messages will be stored until they are retrieved or the scene is changed.

Attributes

id

Scene object ID from the current scene.

msgs

Messages to send.

See also:
Source:
CPSceneObjectContext.scala
def switchScene(id: String, delCur: Boolean): Unit

Switches to the given scene. Note that switch will happen only after the current frame update cycle completes.

Switches to the given scene. Note that switch will happen only after the current frame update cycle completes.

Attributes

delCur

Whether or not to remove the current scene.

id

ID of the scene to switch to.

Source:
CPSceneObjectContext.scala

Concrete methods

def acquireMyFocus(): Unit

Makes the current scene object the owner of the input keyboard focus.

Makes the current scene object the owner of the input keyboard focus.

Attributes

See also:
Source:
CPSceneObjectContext.scala
def deleteMyself(): Unit

Deletes current scene object after this update cycle. Change will be visible only on the next frame update. Note that focus owner will be released if held by the this object.

Deletes current scene object after this update cycle. Change will be visible only on the next frame update. Note that focus owner will be released if held by the this object.

Attributes

Source:
CPSceneObjectContext.scala
def deleteObjectsForTags(tags: String*): Unit

Deletes scene objects with given tags. All tags must be present in the scene object to be deleted. Change will be visible only on the next frame update. Note that focus owner will be released if held by the deleted object.

Deletes scene objects with given tags. All tags must be present in the scene object to be deleted. Change will be visible only on the next frame update. Note that focus owner will be released if held by the deleted object.

Attributes

tags

One or more tags to filter by.

Source:
CPSceneObjectContext.scala
def isFocusOwner: Boolean

Tests whether or not current object is a input keyboard focus owner.

Tests whether or not current object is a input keyboard focus owner.

Attributes

See also:
Source:
CPSceneObjectContext.scala
def isKbKey(key: CPKeyboardKey): Boolean

Checks if the current frame's keyboard event, if any, contains given keyboard key.

Checks if the current frame's keyboard event, if any, contains given keyboard key.

Attributes

key

Keyboard key to check.

See also:

CPKeyboardEvent.key

Source:
CPSceneObjectContext.scala
def switchScene(id: String, delCur: Boolean, cacheProps: (String, AnyRef)*): Unit

Switches to the given scene as well as settings game cache parameters before the switch. Note that switch will happen only after the current frame update cycle completes.

Switches to the given scene as well as settings game cache parameters before the switch. Note that switch will happen only after the current frame update cycle completes.

Attributes

cacheProps

Game cache parameters to set before switching the scene.

delCur

Whether or not to remove the current scene.

id

ID of the scene to switch to.

Source:
CPSceneObjectContext.scala

Inherited methods

def getFrameCount: Long

Gets global frame count for the game.

Gets global frame count for the game.

Attributes

Inherited from:
CPBaseContext
Source:
CPBaseContext.scala
def getFrameMs: Long

Gets the timestamp in milliseconds for the current frame.

Gets the timestamp in milliseconds for the current frame.

This value will be the same for all objects across all callbacks for the entirety of the current frame processing. It is used to provide the time simultaneity across all scene objects at a given frame.

Attributes

Inherited from:
CPBaseContext
Source:
CPBaseContext.scala

Gets game-wide cache. Game-wide cache can be used to share data across scenes.

Gets game-wide cache. Game-wide cache can be used to share data across scenes.

A cache is a map-like type that is used for game-wide and scene-wide user-data containers. The instances of this class are created and managed by the game engine. Scene and game caches can be used to exchange and store user-defined data between frames of the same scene or between scenes of the game. Note that by default these caches are in-memory only and not persistent between game executions. One could, however, add persistence using one of the lifecycle methods available through CPLifecycle type that is extended by both CPSceneObject and CPScene types.

Attributes

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

Gets log instance.

Gets log instance.

Attributes

Inherited from:
CPBaseContext
Source:
CPBaseContext.scala

Gets scene-wide cache. Scene-wide cache gets cleared when scene changes.

Gets scene-wide cache. Scene-wide cache gets cleared when scene changes.

A cache is a map-like type that is used for game-wide and scene-wide user-data containers. The instances of this class are created and managed by the game engine. Scene and game caches can be used to exchange and store user-defined data between frames of the same scene or between scenes of the game. Note that by default these caches are in-memory only and not persistent between game executions. One could, however, add persistence using one of the lifecycle methods available through CPLifecycle type that is extended by both CPSceneObject and CPScene types.

Attributes

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

Gets frame count since the beginning of the current scene.

Gets frame count since the beginning of the current scene.

Attributes

Inherited from:
CPBaseContext
Source:
CPBaseContext.scala
def getStartGameMs: Long

Gets the timestamp in milliseconds of the game start.

Gets the timestamp in milliseconds of the game start.

Attributes

Inherited from:
CPBaseContext
Source:
CPBaseContext.scala
def getStartSceneMs: Long

Gets the timestamp in milliseconds of the current scene start.

Gets the timestamp in milliseconds of the current scene start.

Attributes

Inherited from:
CPBaseContext
Source:
CPBaseContext.scala