{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorSkinSwitcher** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== ECBehaviorSkinSwitcher ====== Behavior element behavior adding support to switch component skins. If a texture name is specified the matching component texture skin is switched instead of switching the skin for the entire component. Switching skins can be used for example with monitors which show an offline skin and if used by the player switch to one or more online skins. Another use case is to create damageable objects which change skin the more they are damaged. To use thie behavior assign one or more skins to it. The first skin is used as the starting skin. By calling setActive() the active skin can be selected using the index of the skin in the list of defined skins. Furthermore activateNext() and activatePrevious() can be used to cycle through skins. Optionally this behavior can be attached to various other behaviors supporting #@LinkApiDocDEDS2_HTML~interfaceDragengine_1_1Scenery_1_1BooleanBehaviorListener.html,BooleanBehaviorListener~@#. By doing so cycling though skins is attached to listener events called by other behaviors. Skin switcher is set by default to wrap index around at the begin and end of the skin list. This allows to indefinitely cycle through all skins. By setting the "clamp" element class property to true the skins can cycle only once not wrapping around. ====== Instance Counts ====== Multiple instances of ''ECBehaviorSkinSwitcher'' can be used for example to switch skins of multiple component textures. Use the behavior identifier to tell them apart. ====== Element Class Properties ====== Element class properties have the prefix ''skinSwitcher.'' or ''skinSwitcher(id).'' if id is not empty. ===== texture ===== Name of texture in component to switch skin. If empty string switch skin of component itself. * Full name: ''skinSwitcher.texture'' or ''skinSwitcher(id).texture'' * Type: string * Default Value: empty string * Example (*.deeclass): locked ===== skins ===== List of skins to cycle through. At least one skin is required to be defined for this property to be valid. * Full name: ''skinSwitcher.skins'' or ''skinSwitcher(id).skins'' * Type: List of string * Default value: empty list * File Pattern: ''*.deskin'' (all skin modules) * Example (*.deeclass): /content/skins/locked.deskin /content/skins/unlocked.deskin ===== clamp ===== If the skin index reaches either end of the list it wraps around to the other end (from last to first and vice versa). If clamp is true wrapping around is disabled keeping the index at the last respectively first index. * Full name: ''skinSwitcher.clamp'' or ''skinSwitcher(id).clamp'' * Type: boolean * Default value: ''false'' * Example (*.deeclass): true ===== activeSkin ===== Index of first skin from //skins// property to show. Index has to be in the range from 0 to //skins.count-1//. * Full name: ''skinSwitcher.activeSkin'' or ''skinSwitcher(id).activeSkin'' * Type: integer * Default Value: ''0'' * Example (*.deeclass): 1 ====== Behavior Tree Actions ====== This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''skinSwitcher'' with ''skinSwitcher(id)''. ===== skinSwitcher.update ===== Update skin switcher. ^Parameter^Value^Description^ |active|''next'', ''previous'', ''first'', ''last'', integer|Set active skin to next, previous, first, last or index| This is an example of using this action: next ===== skinSwitcher.check ===== Check one or more skin switcher parameters. Action succeeds if all parameter value matches their respective skin switcher parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a skin switcher parameter matches (or not). ^Parameter^Value^Description^ |active|''first'', ''last'', integer|Active skin is the first, last or matches index| |active.not|''first'', ''last'', integer|Active skin is not the first, last or matches index| |active.less|integer|Index of active skin is less than value| |active.greater|integer|Index of active skin is greater than value| |count|integer|Skin count matches value| |count.less|integer|Skin count is less than value| |count.greater|integer|Skin count is greater than value| |wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled| This is an example of using this action: last ====== Behavior Tree Conditions ====== This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''skinSwitcher'' with ''skinSwitcher(id)''. ===== skinSwitcher.check ===== Check one or more skin switcher parameters. Conditions returns true if all parameter value match their respective skin switcher parameter. This condition is typically used to run an action or sequence of actions as long as skin switcher conditions are true. ^Parameter^Value^Description^ |skinSwitcher.active|''first'', ''last'', integer|Active skin is the first, last or matches index| |skinSwitcher.active.not|''first'', ''last'', integer|Active skin is not the first, last or matches index| |skinSwitcher.active.less|integer|Index of active skin is less than value| |skinSwitcher.active.greater|integer|Index of active skin is greater than value| |skinSwitcher.count|integer|Skin count matches value| |skinSwitcher.count.less|integer|Skin count is less than value| |skinSwitcher.count.greater|integer|Skin count is greater than value| This is an example of using this condition: last skinSwitcher.check ====== State Machine Actions ====== Same as [[#behavior_tree_actions|Behavior Tree Actions]]. ====== State Machine Conditions ====== Same as [[#behavior_tree_conditions|Behavior Tree Conditions]]. ====== State Machine Events ====== This behavior sends these state machine events. If behavior has non-empty identifier replace ''skinSwitcher'' with ''skinSwitcher(id)''. ===== skinSwitcher.changed ===== Active skin changed. ====== Required Behaviors ====== * [[behavior_component|ECBehaviorComponent]] ====== Optional Behaviors ====== * [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use. * [[behavior_statemachine|ECBehaviorStateMachine]]: Add actions and conditions for state machine to use and events to send to the state machine. ====== Persistency ====== This behavior does support element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorSkinSwitcher.html,ECBehaviorSkinSwitcher~@#. Since DragonScript Module Version ''1.3'' ====== Use Cases ====== * Create monitors which show an offline skin and if used by the player switch to one or more online skins. * Create damageable objects which change skin the more they are damaged. * Create information panels for puzzles showing the player the current state he needs to solve. ====== Element Class Example ====== The example below switches the skin of a texture if the animated state become activate: class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorTwoStateAnimated animated public var ECBehaviorSkinSwitcher skinSwitcher public func new() // Create component to switch texture component = ECBehaviorComponent.new(this) collider = ECBehaviorCollider.new(this, component) // Create animated behavior which is used as trigger for the skin switcher animated = ECBehaviorTwoStateAnimated.new(this, component) // Create skin switcher for texture "display". If empty string is used instead // the skin is switched for the entire component skinSwitcher = ECBehaviorSkinSwitcher.new(this, component) skinSwitcher.getTexture().setValue("display") // Add skins to load. This example uses an "off" and an "on" skin. Other examples // could use multiple skins to cycle through. For switching multiple skins more // complex logic is usually required so it is better if you add your own listeners // do the appropriate switching. The provided listeners are suited for the simple // case of switching between two skins skinSwitcher.getSkins().add("/content/skins/displayOff.deskin") skinSwitcher.getSkins().add("/content/skins/displayOn.deskin") // Add listener factory to ECBehaviorTwoStateAnimated. This makes the skin switch // whenever the animated behavior enters or leaves "activated" state. This is only // one possible way to connect to the ECBehaviorTwoStateAnimated but a common one. skinSwitcher.listen(animated) end end ====== Behavior Factory ====== Using element class supporting adding behaviors the behavior can be added like this: second second second locked ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]