Class: DisplayPool

rune.display.DisplayPool(container, factory)

The DisplayPool class extends DisplayGroup with reusable members. acquire() activates an available member or creates one through the factory. release() hides and deactivates a member without removing it from the container. Members added through addMember() or include() are considered in use until released. Member lists contain both available and acquired objects; callers must filter inactive members when performing collision tests. The caller resets object-specific state before using an acquired member.

Constructor

new DisplayPool(container, factory)

Creates a display group that reuses its members.
Parameters:
Name Type Description
container rune.display.DisplayObjectContainer Container for all members.
factory function Creates a new DisplayObject, with this pool as its scope.
Source:
Throws:
If the factory is not a function.
Type
TypeError

Extends

Members

active :boolean

Whether the group is active (true) or not (false). Inactive groups are not automatically updated by the group manager.
Type:
  • boolean
Inherited From:
Default Value:
  • true
Source:

(readonly) application :rune.system.Main

Reference to the application's entry point class, ie. the main class of the application. Useful for accessing the application's subsystem.
Type:
  • rune.system.Main
Inherited From:
Source:

(readonly) cameras :rune.camera.Cameras

Reference to the current scene's camera system.
Type:
Inherited From:
Source:

(readonly) container :rune.display.DisplayObject

Reference to the display object container to which the group is linked. When new members are added to the group, they are also added to the display object container's display list.
Type:
Inherited From:
Source:

(readonly) gamepads :rune.input.Gamepads

Reference to the application's subsystem for connected gamepad devices.
Type:
Inherited From:
Source:

(readonly) keyboard :rune.input.Keyboard

Reference to the subsystem representing the keyboard input.
Type:
Inherited From:
Source:

(readonly) numAvailable :number

The number of released members available for reuse.
Type:
  • number
Source:

(readonly) numMembers :number

The number of members included in the group. Note that this number is not necessarily the same as the number of children in the display object container to which the group is linked.
Type:
  • number
Inherited From:
Source:

useQuadtree :boolean

Whether the group should use a quad tree to improve hit testing performance. Note that the quad tree can not guarantee noticeably better performance, but it should be evaluated when you experience performance problems with the quad tree disabled.
Type:
  • boolean
Inherited From:
Source:

Methods

acquire() → {rune.display.DisplayObject}

Obtains a member and makes it active and visible. If none is available, the factory creates a DisplayObject that is added to the group and container. The factory must return an object that does not already belong to a group. Velocity, position and other object-specific state are not reset.
Source:
Throws:
  • If the pool is disposed or has no container.
    Type
    Error
  • If the factory does not return an ungrouped DisplayObject.
    Type
    TypeError
Returns:
The acquired member.
Type
rune.display.DisplayObject

addMember(member) → {boolean}

Adds a member to the display group. Note that attempts to add existing members are denied. The method always returns a boolean that indicates whether the extension was successful (true) or not (false). When an item is added to a group, it is automatically removed from any other groups, and it is also removed from other display lists. This means that an object can only be a member of one group at a time and that it is always available in the group's container object view list as long as it is a member of that group.
Parameters:
Name Type Description
member rune.display.DisplayObject Prospect to add.
Inherited From:
Source:
Returns:
Type
boolean

dispose() → {undefined}

Disposes all members, both acquired and available, and clears pool references.
Overrides:
Source:
Returns:
Type
undefined

forEachMember(callback, scope) → {undefined}

Executes a callback method for each member of the group. Reference to the current member and its member index are sent to the callback method as arguments.
Parameters:
Name Type Description
callback function Call function.
scope Object Scope of execution.
Inherited From:
Source:
Returns:
Type
undefined

getMemberAt(index) → {rune.display.DisplayObject}

Retrieves a member object at a specific index. Note that the member index is not necessarily the same as the object's child index in the display object container.
Parameters:
Name Type Description
index number The index position of the member object.
Inherited From:
Source:
Throws:
Throws if the index does not exist in the member list.
Type
RangeError
Returns:
The member object at the specified index position.
Type
rune.display.DisplayObject

getMembers() → {Array.<rune.display.DisplayObject>}

Retrieves the list of all members. This method is primarily intended for internal use. Consider it read-only, as changes in the structure can cause problems for the group.
Inherited From:
Source:
Returns:
Type
Array.<rune.display.DisplayObject>

getMembersCloseTo(obj) → {Array.<rune.display.DisplayObject>}

If the useQuadtree property is set to true, only member objects that are in close proximity to the argument object are returned; otherwise a list of all members is returned.
Parameters:
Name Type Description
obj rune.display.DisplayObject Main object.
Inherited From:
Source:
Returns:
Type
Array.<rune.display.DisplayObject>

hasMember(prospect) → {boolean}

Returns whether an object is a member of the group (true) or not (false.)
Parameters:
Name Type Description
prospect rune.display.DisplayObject Main object.
Inherited From:
Source:
Returns:
Type
boolean

hitTest(obj, callbackopt, scopeopt) → {boolean}

Performs hit detection between an object and all members of the group. For each hit, a callback method is also executed, which attaches the two objects that collide as arguments to the method.
Parameters:
Name Type Attributes Description
obj rune.display.DisplayObject | rune.display.DisplayGroup | rune.geom.Point | Array Object to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
Returns true if any hit was found, otherwise false.
Type
boolean

hitTestAndSeparate(obj, callbackopt, scopeopt) → {boolean}

Performs hit detection between an object and all members of the group. If a hit is detected, the objects are separated according to their physical properties. For each hit, a callback method is also executed, which attaches the two objects that collide as arguments to the method.
Parameters:
Name Type Attributes Description
obj rune.display.DisplayObject | rune.display.DisplayGroup | Array Object to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
Returns true if any hit was found, otherwise false.
Type
boolean

hitTestAndSeparateContentOf(array, callbackopt, scopeopt) → {boolean}

Evaluates and handles collisions between group member hitboxes and the hitboxes of objects in an array.
Parameters:
Name Type Attributes Description
array Array The array to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestAndSeparateGroup(group, callbackopt, scopeopt) → {boolean}

Performs hit detection between members of this and another group. If a hit is detected, the objects are separated based on their physical properties. For each hit, a callback method is also executed, which attaches the two objects that collide as arguments to the method.
Parameters:
Name Type Attributes Description
group rune.display.DisplayGroup Group to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
True if there was a collision, otherwise false.
Type
boolean

hitTestAndSeparateObject(obj, callbackopt, scopeopt) → {boolean}

Performs hit detection between members of this group and another display object. If a hit is detected, the objects are separated based on their physical properties. For each hit, a callback method is also executed, which attaches the two objects that collide as arguments to the method.
Parameters:
Name Type Attributes Description
obj rune.display.DisplayObject Object to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestContentOf(array, callbackopt, scopeopt) → {boolean}

Evaluates collision between the hitboxes of group members and the hitboxes of objects in an array.
Parameters:
Name Type Attributes Description
array Array The array to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestGroup(group, callbackopt, scopeopt) → {boolean}

Hit detect all members of the group against the members of (the same or) another group.
Parameters:
Name Type Attributes Description
group rune.display.DisplayGroup The group to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestObject(obj, callbackopt, scopeopt) → {boolean}

Hit detect all members of the group against another display object.
Parameters:
Name Type Attributes Description
obj rune.display.DisplayObject The display object to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestPoint(point, callbackopt, scopeopt) → {boolean}

Hit Detect all members of the group against a point. The method returns true if the point overlaps one of the group members, otherwise false is returned.
Parameters:
Name Type Attributes Description
point rune.geom.Point Point to test against.
callback function <optional>
Method that is called when a collision is detected.
scope Object <optional>
Scope of execution of the callback method.
Inherited From:
Source:
Returns:
Type
boolean

init() → {undefined}

This method is automatically called once by the group manager when the group is created, or added. The method is public but should be considered internal. External calls should only be made if 1. The group is disabled, or 2. If the group is not added to a manager.
Inherited From:
Source:
Returns:
Type
undefined

postUpdate(step) → {undefined}

This method is called automatically after the group's main update method is completed. The method can be overridden and used to complete closing processes just before the next update.
Parameters:
Name Type Description
step number Current time step.
Inherited From:
Source:
Returns:
Type
undefined

preUpdate(step) → {undefined}

This method is called just before the group's update method and performs processes that must be completed before the group's main update process begins. Avoid overriding and modifying this method.
Parameters:
Name Type Description
step number Current time step.
Inherited From:
Source:
Returns:
Type
undefined

release(member) → {boolean}

Hides and deactivates a member while keeping it in the group and container. Duplicate releases, nonmembers and calls after disposal are ignored. Object-specific state and the movable property are left unchanged.
Parameters:
Name Type Description
member rune.display.DisplayObject Member to make available for reuse.
Source:
Returns:
Whether the member was released.
Type
boolean

removeMember(member, dispose) → {rune.display.DisplayObject}

Removes a member from the pool and container, including its availability.
Parameters:
Name Type Description
member rune.display.DisplayObject Member to remove.
dispose boolean Whether to destroy the removed member.
Overrides:
Source:
Returns:
The removed member, or null when disposed.
Type
rune.display.DisplayObject

removeMembers(dispose) → {undefined}

Removes all members from the group.
Parameters:
Name Type Description
dispose boolean Whether the members should be destroyed when they are removed.
Inherited From:
Source:
Returns:
Type
undefined

update(step) → {undefined}

This method represents the group's main update process. The method can be overridden in order to add custom logic.
Parameters:
Name Type Description
step number Current time step.
Inherited From:
Source:
Returns:
Type
undefined