CPSceneObjectContext

org.cosplay.CPSceneObjectContext

Scene object context during frame update.

This type is the main access point to the most of CosPlay functionality for the scene objects comprising the gameplay. On each 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

Value members

Abstract methods

def acquireFocus(id: String): Unit

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

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

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

Value parameters

id

ID of the scene object.

Attributes

See also
Source
CPSceneObjectContext.scala
def addObject(obj: CPSceneObject, replace: Boolean): 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.

Value parameters

obj

Scene object to add.

replace

If the scene object with the same ID as given object exists, this flag allows to remove the existing scene object first thus effectively replace it with the new scene object with the same ID. The default value is false.

Attributes

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

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

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

Value parameters

delCur

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

newSc

A scene to add.

replace

If the scene with the same ID as a new one already exists, this flag allows to delete the existing scene first thus effectively replacing the existing scene with the new one with the same ID. This is convenient shortcut for removing the scene manually before re-adding it again, if required. The default value is false. Note that you cannot replace the current scene as you cannot remove the current scene.

switchTo

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

Attributes

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.

Value parameters

zs

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

Attributes

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.

Value parameters

zs

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

Attributes

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.

Value parameters

zs

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

Attributes

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

Consumes current frame's keyboard event, if any. Consumption of the keyboard event means that any subsequent calls to getKbEvent method within the same frame from other scene objects will return None. It is important to remember that the order of the scene objects notifications (i.e. calling CPSceneObject.update, CPSceneObject.monitor and CPSceneObject.render callbacks) is undefined and one cannot rely on any assumed order. In other words, the only guarantee is that if keyboard event is consumed, for example, at "update" phase, none of the scene objects within the same frame in "monitor" and "render" phases will get the keyboard event.

Consumes current frame's keyboard event, if any. Consumption of the keyboard event means that any subsequent calls to getKbEvent method within the same frame from other scene objects will return None. It is important to remember that the order of the scene objects notifications (i.e. calling CPSceneObject.update, CPSceneObject.monitor and CPSceneObject.render callbacks) is undefined and one cannot rely on any assumed order. In other words, the only guarantee is that if keyboard event is consumed, for example, at "update" phase, none of the scene objects within the same frame in "monitor" and "render" phases will get the keyboard event.

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

Attributes

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.

Value parameters

tags

One or more tags to filter by.

Attributes

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.

Value parameters

id

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

Attributes

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.

Value parameters

id

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

Attributes

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.

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

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.

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

Attributes

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

Gets scene object with given ID or None if such object cannot be found.

Gets scene object with given ID or None if such object cannot be found.

Value parameters

id

ID of the scene object to get.

Attributes

Source
CPSceneObjectContext.scala
def getObjects: Iterable[CPSceneObject]

Gets all scene objects in the current scene.

Gets all scene objects in the current scene.

Attributes

Source
CPSceneObjectContext.scala
def getObjectsForTags(tags: Set[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.

Value parameters

tags

One or more tags to filter by.

Attributes

Source
CPSceneObjectContext.scala

Gets the scene object this context is currently associated with.

Gets the scene object this context is currently associated with.

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.

Value parameters

id

ID of the scene object to get.

Attributes

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.

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

Value parameters

id

ID of the scene object.

Attributes

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

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

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

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

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).

Value parameters

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.

Attributes

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.

Value parameters

f

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

Attributes

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.

Value parameters

id

Scene object ID from the current scene.

msgs

Messages to send.

Attributes

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.

Value parameters

delCur

Whether or not to remove the current scene.

id

ID of the scene to switch to.

Attributes

Source
CPSceneObjectContext.scala

Concrete methods

def acquireMyFocus(): Unit

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

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

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

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.

Value parameters

tags

One or more tags to filter by.

Attributes

Source
CPSceneObjectContext.scala
def isFocusOwner: Boolean

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

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

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

Attributes

See also
Source
CPSceneObjectContext.scala
def isFocusOwner(id: String): Boolean

Tests whether or not scene object with given ID is a keyboard focus owner.

Tests whether or not scene object with given ID is a keyboard focus owner.

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

Value parameters

id

Scene object ID to test for keyboard focus ownership.

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. Returns true only and only if current frame has a key press and its keyboard key is equal to the given key.

Checks if the current frame's keyboard event, if any, contains given keyboard key. Returns true only and only if current frame has a key press and its keyboard key is equal to the given key.

Note that if the focus is not held by any scene object, i.e. was acquired and released or not acquired at all, all objects that call getKbEvent function will receive the same result within the current frame, i.e. the pressed key or None if there wasn't a key press. If keyboard focus was acquired and is held by the scene object - only that object will receive a result from getKbEvent function call while all other scene objects will get None as if no key press happened.

Value parameters

key

Keyboard key to check.

Attributes

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.

Value parameters

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.

Attributes

Source
CPSceneObjectContext.scala

Inherited methods

def getFrameCount: Long

Gets global frame count for the game. Global frame count spans all scenes.

Gets global frame count for the game. Global frame count spans all scenes.

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
def getLog: CPLog

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
def getSceneFrameCount: Long

Gets frame count since the beginning of the current scene. If the same scene gets deactivated and activated again its frame count will reset to zero.

Gets frame count since the beginning of the current scene. If the same scene gets deactivated and activated again its frame count will reset to zero.

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