Class TCastleBehavior
Unit
Declaration
type TCastleBehavior = class(TCastleComponent)
Description
Behaviors can be attached to TCastleTransform to perform specific logic, for example implement creature movement. This implements a simple component-system for TCastleTransform. Using behaviors allows to attach independent functionality like inventory, being alive (because not everything alive needs inventory, not everything with inventory needs to be alive), creature logic and more. CGE provides implementation for some behaviors, and you can create your own too.
You implemement a descendant of TCastleBehavior, typically overriding its Update method, and add it to TCastleTransform by TCastleTransform.AddBehavior. Inside TCastleBehavior, access the TCastleTransform instances by Parent.
The API of TCastleBehavior is deliberately a subset of the TCastleTransform API, for example both have Update method. Using TCastleBehavior is just simpler and more efficient, as TCastleBehavior doesn't have own transformation, children and it cannot render something. If this is too limiting, remember you can always implement more powerful behaviors by creating TCastleTransform descendants instead of TCastleBehavior descendants, and accessing the TCastleTransform.UniqueParent from a child.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleBehavior
Overview
Methods
![]() |
procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); virtual; |
![]() |
procedure ParentChanged; virtual; |
![]() |
procedure SingleInstanceOfBehavior; |
![]() |
procedure SingleInstanceOfBehavior(const BehaviorClass: TCastleBehaviorClass); |
Properties
![]() |
property Parent: TCastleTransform read FParent; |
Description
Methods
![]() |
procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); virtual; |
|
Continuously occuring event, for various tasks. Parameters
| |
![]() |
procedure ParentChanged; virtual; |
|
Called after Parent changed, at the end of TCastleTransform.AddBehavior, TCastleTransform.RemoveBehavior. | |
![]() |
procedure SingleInstanceOfBehavior; |
|
Used to check that the one and only instance of BehaviorClass in Parent is Self. | |
![]() |
procedure SingleInstanceOfBehavior(const BehaviorClass: TCastleBehaviorClass); |
|
Used to check that the one and only instance of current class type is Self. This is a simpler overload of | |
Properties
![]() |
property Parent: TCastleTransform read FParent; |
|
Parent TCastleTransform of this behavior. Change it by doing TCastleTransform.AddBehavior, TCastleTransform.RemoveBehavior.
| |
Generated by PasDoc 0.16.0.

