Description

Traits enable sharing logic between objects without the need of inheritance.

A trait is divided into five lifecycle-steps:

  1. ADD: Adding a trait to an instance
  2. UPDATE: Updating a trait
  3. DRAW: Drawing a trait
  4. TIMER: A timer has reached zero
  5. REMOVE: Removing a trait from an instance

Each trait must define a callback-script, in which the logic for each of the above lifecycle-steps is defined. This script is virtually the object counterpart of the trait system. A trait is therefore just as powerful as an object, with the added benefit of being able to assign multiple traits to an object, while an object can have only one parent object.

Code-snippet that shows the setup of a trait: snippet_pp_trait_define

Code-snippet that shows a trait-script in action: snippet_pp_trait_callback

Documentation: API

Changelog:

1.1.0:

  • The 'obj_pp_demo_pig'-object no longer inherits from 'obj_pp_traitable' to show, that there is no need for inheritance to share a trait
  • New function: scr_pp_trait_nearest
  • New function: scr_pp_trait_furthest

(C)opyright for the sprites: Kacper Woźniak

More info

End User Licence Agreement (EULA).

Age Rating: 4+

Version

GMS2 - Version 1.1.0. Published April 13, 2018

Loading, please wait

Package contents

Loading, please wait

What is the issue?

Loading, please wait

Back to Top