CPLifecycle

org.cosplay.CPLifecycle
See theCPLifecycle companion object
trait CPLifecycle

Lifecycle type for scenes and scene objects.

Objects supporting this lifecycle transition their states as follows:

 +---------+   +------------+   +-----------+   +-------------+   +------------+
 | LF_INIT |-->| LF_STARTED |-->| LF_ACTIVE |-->| LF_INACTIVE |-->| LF_STOPPED |
 +---------+   +------------+   +-----------+   +-------------+   +------------+
                                      |                   |
                                      +---<-----<----<----+

Specifically, lifecycle objects are started and stopped only once but they can transition from active to inactive state more than once. When a scene starts it and its scene objects will be started, if they haven't been started before, and activated. When switching to another scene, the current scene and its scene objects will be deactivated. Scene and scene objects get stopped when either the entire game exits or an object gets removed.

The typical use case for the lifecycle events is resource initialization and disposal, logging, stats collections, etc. It is especially important in online games or the games that pull or stream online assets.

Note that when overriding the following callback methods make sure to call super:

Attributes

Companion
object
Source
CPLifecycle.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Concrete methods

final def getState: State

Gets current lifecycle state.

Gets current lifecycle state.

Attributes

Source
CPLifecycle.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

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

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

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

Source
CPLifecycle.scala