Class: InteractiveObject

(abstract) rune.display.InteractiveObject(xopt, yopt, widthopt, heightopt)

The InteractiveObject class is the abstract base class for all display objects with which the user can interact, using the mouse, keyboard, or other user input device.

Constructor

(abstract) new InteractiveObject(xopt, yopt, widthopt, heightopt)

Creates a new InteractiveObject.
Parameters:
Name Type Attributes Default Description
x number <optional>
0.0 The x coordinate of the top-left corner of the rectangle.
y number <optional>
0.0 The y coordinate of the top-left corner of the rectangle.
width number <optional>
0.0 The y coordinate of the top-left corner of the rectangle.
height number <optional>
0.0 The height of the rectangle, in pixels.
Source:

Extends

Members

active :boolean

Whether the object should be automatically updated by its parent object. Inactive objects are still rendered. the default value is true.
Type:
  • boolean
Default Value:
  • true
Source:

allowCollisions :number

Describes the type of collision to which the object responds.
Type:
  • number
Default Value:
  • rune.physics.Space.ANY
Source:

(readonly) application :rune.system.Application

Reference to the application's entry point class, ie. the main class of the application. Useful for accessing the application's subsystem.
Type:
Source:

bottom :number

The sum of the y and height properties.
Type:
  • number
Inherited From:
Source:

bottomLeft :rune.geom.Rectangle

The location of the Rectangle object's bottom-left corner, determined by the values of the left and bottom properties.
Type:
Inherited From:
Source:

bottomRight :rune.geom.Rectangle

The location of the Rectangle object's bottom-right corner, determined by the values of the right and bottom properties.
Type:
Inherited From:
Source:

center :rune.geom.Point

The center point of the rectangle object.
Type:
Inherited From:
Source:

centerX :number

The x coordinate of the center of the object.
Type:
  • number
Inherited From:
Source:

centerY :number

The y coordinate of the center of the object.
Type:
  • number
Inherited From:
Source:

elasticity :number

The elasticity of the object. Used to calculate the impact when two objects collide with each other. The greater the value, the more bouncy the object behaves.
Type:
  • number
Default Value:
  • 0.0
Source:

(readonly) gamepads :rune.input.Gamepads

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

height :number

Indicates the height of the object, in pixels.
Type:
  • number
Overrides:
Source:

(readonly) hitbox :rune.display.Hitbox

Represents a boundary box used for collision detection. Use the object's set() method to specify position and size. By default, it is positioned at 0, 0 and has the same size as the interactive object.
Type:
Source:

immovable :boolean

Whether the object may change position when it collides with another object.
Type:
  • boolean
Source:

immovable :boolean

Whether the object may change position when it collides with another object.
Type:
  • boolean
Source:

(readonly) keyboard :rune.input.Keyboard

Reference to the keyboard manager. Use this reference to read the state of any keyboard key.
Type:
Source:

left :number

The x coordinate of the top-left corner of the rectangle.
Type:
  • number
Inherited From:
Source:

mass :number

The mass of the object. This value is used to calculate the impact when the object collides with another object with mass.
Type:
  • number
Default Value:
  • 1.0
Source:
The sum of the x and width properties.
Type:
  • number
Inherited From:
Source:

scaleX :number

Indicates the horizontal scale (percentage) of the object as applied from the upper left corner. 1.0 is 100% scale.
Type:
  • number
Source:

scaleY :number

Indicates the vertical scale (percentage) of an object as applied from the upper left corner. 1.0 is 100% scale.
Type:
  • number
Source:

size :rune.geom.Point

The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
Type:
Inherited From:
Source:

(readonly) states :rune.state.States

A finite-state machine. Use this reference to apply isolated behavioral states to the object.
Type:
Source:

sticky :boolean

Used in collision handling. If an object is sticky, other objects placed on top of the object may follow its movement. This is useful when developing platform games as a player can, for example, ride on moving platforms or other objects.
Type:
  • boolean
Default Value:
  • false
Source:

top :number

The y coordinate of the top-left corner of the rectangle.
Type:
  • number
Inherited From:
Source:

topLeft :rune.geom.Point

The location of the Rectangle object's top-left corner, determined by the x and y coordinates of the point.
Type:
Inherited From:
Source:

topRight :rune.geom.Point

The location of the Rectangle object's top-right corner, determined by the x and y coordinates of the point.
Type:
Inherited From:
Source:

(readonly) touched :number

Whether the object touched another object in the previous update. See touching for more information.
Type:
  • number
Source:
See:

touching :number

Whether the object touches another object and in such cases in which directions. The value is represented by a bit field and thus several directions can be true at the same time.
Type:
  • number
Source:
See:

(readonly) velocity :rune.physics.Velocity

The velocity of the object. This object is used to calculate the object's direction of travel, as well as its speed. Note that the object is only used when the movable property is set to true.
Type:
Source:

width :number

Indicates the width of the object, in pixels.
Type:
  • number
Overrides:
Source:

x :number

The horizontal coordinate of the point. The default value is 0.
Type:
  • number
Inherited From:
Source:

y :number

The vertical coordinate of the point. The default value is 0.
Type:
  • number
Inherited From:
Source:

Methods

containsPoint(point) → {boolean}

Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.
Parameters:
Name Type Description
point rune.geom.Point The point, as represented by its x and y coordinates.
Inherited From:
Source:
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
Type
boolean

containsRectangle(rect) → {boolean}

Determines whether the Rectangle object specified by the rect parameter is contained within this Rectangle object. A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
Parameters:
Name Type Description
rect rune.geom.Rectangle The Rectangle object being checked.
Inherited From:
Source:
Returns:
A value of true if the Rectangle object that you specify is contained by this Rectangle object; otherwise false.
Type
boolean

dispose() → {undefined}

Process that prepares the object for removal. All internal processes are stopped and allocated memory will be cleared by the garbage collector at the next sweep.
Source:
Returns:
Type
undefined

distance(point) → {number}

Returns the distance between the current and specified point.
Parameters:
Name Type Description
point rune.geom.Point The specified point.
Inherited From:
Source:
Returns:
Type
number

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

Evaluates whether the object's hitbox overlaps or intersects with the parameter object's hitbox.
Parameters:
Name Type Attributes Description
obj rune.display.Stage | rune.display.InteractiveObject | rune.display.DisplayGroup | rune.tilemap.TilemapLayer | rune.geom.Point | Array The object to be evaluated.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Source:
Returns:
Type
boolean

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

Evaluates and resolves collision between the object's hitbox and the given argument object.
Parameters:
Name Type Attributes Description
obj rune.display.Stage | rune.display.InteractiveObject | rune.display.DisplayGroup | rune.tilemap.TilemapLayer | Array The object to be evaluated.
callback function <optional>
Executed automatically in case of overlap.
scope Object <optional>
Scope within the callback method must be executed.
Source:
Returns:
Type
boolean

hitTestAndSeparateChildrenOf(parent, callbackopt, scopeopt) → {boolean}

Evaluates and resolves collision between this object's hitbox and the hitbox of all children of the specified argument object. Note that this method does not include the actual argument object, only its children.
Parameters:
Name Type Attributes Description
parent rune.display.DisplayObjectContainer The container object to be evaluated.
callback function <optional>
Executed automatically in case of overlap.
scope Object <optional>
Scope within the callback method must be executed.
Source:
Returns:
Type
boolean

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

Evaluates and resolves hitbox-based collision between the object and other objects in a list structure (array).
Parameters:
Name Type Attributes Description
array Array The array object to be evaluated.
callback function <optional>
Executed automatically in case of overlap.
scope Object <optional>
Scope within the callback method must be executed.
Source:
Returns:
Type
boolean

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

Evaluates whether this object's hitbox overlaps or intersects any hitbox of the members of the specified group object.
Parameters:
Name Type Attributes Default Description
group rune.display.DisplayGroup Group to evaluate.
callback function <optional>
null Executed in case of collision.
scope Object <optional>
this Scope of execution for callback method.
Source:
Returns:
True if there was a collision, otherwise false.
Type
boolean

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

Evaluates whether the object's bounding box overlaps a bounding box of another object and in the event of a collision, the objects are separated in order to resolve the collision.
Parameters:
Name Type Attributes Default Description
obj rune.display.InteractiveObject The interactive object to test against.
callback function <optional>
null Executed in case of collision.
scope Object <optional>
this Scope of execution for callback method.
Source:
Returns:
True if there was a collision, otherwise false.
Type
boolean

hitTestAndSeparateTilemapLayer(layer, callbackopt, scopeopt) → {boolean}

Evaluates, and resolves, collision between this object's hitbox and any solid tile within the specified tilemap layer.
Parameters:
Name Type Attributes Default Description
layer rune.tilemap.TilemapLayer Layer to evaluate.
callback function <optional>
null Executed in case of collision.
scope Object <optional>
this Scope of execution for callback method.
Source:
Returns:
True if there was a collision, otherwise false.
Type
boolean

hitTestChildrenOf(parent, callbackopt, scopeopt) → {boolean}

Evaluates the bounding box of the interactive object to see if it overlaps or intersects the bounding box of any of the container object's children. The method returns true if this happens to any of the children. The callback method is activated for each child that is overlapped.
Parameters:
Name Type Attributes Description
parent rune.display.DisplayObjectContainer Container object whose children are to be checked.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Source:
Throws:
If the specified argument is not of type DisplayObjectContainer.
Type
Error
Returns:
If any of the container object's children are overlapped by this object, true is returned, otherwise false.
Type
boolean

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

Evaluates whether the object's hitbox overlaps or intersects the hitbox of any other object in the specified list. The list can contain a mixture of data types, provided that each data type is supported by the hitTest method.
Parameters:
Name Type Attributes Description
array Array Container object whose children are to be checked.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Source:
Throws:
If the specified argument is not of type DisplayObjectContainer.
Type
Error
Returns:
If any of the container object's children are overlapped by this object, true is returned, otherwise false.
Type
boolean

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

Evaluates whether the object's hitbox overlaps or intersects the hitbox of any member of a group. The evaluation is carried out against all members of the group. The method returns true if there was an overlap, false otherwise.
Parameters:
Name Type Attributes Description
group rune.display.DisplayGroup Group to evaluate.
callback function <optional>
Executed automatically in case of overlap.
scope Object <optional>
Scope within the callback method must be executed.
Source:
Returns:
Type
boolean

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

Evaluates the bounding box of the interactive object to see if it overlaps or intersects with the bounding box of the obj interactive object.
Parameters:
Name Type Attributes Description
obj rune.display.InteractiveObject The interactive object to test against.
callback function <optional>
Executed in case of collision.
scope Object <optional>
Scope of execution for callback method.
Source:
Returns:
true if the bounding boxes of the interactive objects intersect; false if not.
Type
boolean

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

Evaluates the bounding box of the interactive object to see if it overlaps or intersects with a point object.
Parameters:
Name Type Attributes Description
point rune.geom.Point The point object to test against.
callback function <optional>
Executed in case of collision.
scope Object <optional>
Scope of execution for callback method.
Source:
Returns:
true if the display object overlaps or intersects with the specified point; false otherwise.
Type
boolean

hitTestTilemapLayer(layer, callbackopt, scopeopt) → {boolean}

Evaluates whether the object's hitbox overlaps or intersects a solid tile within a tilemap layer.
Parameters:
Name Type Attributes Description
layer rune.tilemap.TilemapLayer Layer to evaluate.
callback function <optional>
Executed automatically in case of overlap.
scope Object <optional>
Scope within the callback method must be executed.
Source:
Returns:
Type
boolean

interpolate(point, fractionopt, outputopt) → {rune.geom.Point}

Determines a point between two specified points. The parameter fraction determines where the new interpolated point is located relative to the two end points.
Parameters:
Name Type Attributes Description
point rune.geom.Point The second point.
fraction number <optional>
The level of interpolation between the two points.
output rune.geom.Point <optional>
Save results to this object.
Inherited From:
Source:
Returns:
The new, interpolated point.
Type
rune.geom.Point

intersection(toIntersect, outputopt) → {rune.geom.Rectangle}

If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
Parameters:
Name Type Attributes Description
toIntersect rune.geom.Rectangle The Rectangle object to compare against to see if it intersects with this Rectangle object.
output rune.geom.Rectangle <optional>
A Rectangle object to store the intersection results in.
Inherited From:
Source:
Returns:
A Rectangle object that equals the area of intersection.
Type
rune.geom.Rectangle

intersects(toIntersect) → {boolean}

Determines whether the object specified in the toIntersect parameter intersects with this Rectangle object.
Parameters:
Name Type Description
toIntersect rune.geom.Rectangle The Rectangle object to compare against this Rectangle object.
Inherited From:
Source:
Returns:
A value of true if the specified object intersects with this Rectangle object; otherwise false.
Type
boolean

isTouching(direction) → {boolean}

Test whether the object touches another object in one or more directions. The test does not tell what the object touches, only whether it does so (true) or not (false).
Parameters:
Name Type Description
direction number Bit field with directions to check.
Source:
Returns:
Type
boolean

justTouched(direction) → {boolean}

Tests if the object touched other objects during the previous update.
Parameters:
Name Type Description
direction number Bit field with directions to check.
Source:
Returns:
Type
boolean

moveTo(x, y) → {undefined}

Moves an object to the specified position (x and y coordinates). This method can be used when an object needs to be moved without physical limitations.
Parameters:
Name Type Description
x number X coordinate to move to.
y number Y coordinate to move to.
Source:
Returns:
Type
undefined

postUpdate(step) → {undefined}

This method is activated immediately after the object's main update loop is completed. The method performs certain processes that sum up the current update, but also has the purpose of protecting these processes from being deactivated when the update method is overridden.
Parameters:
Name Type Description
step number Fixed time step.
Source:
Returns:
Type
undefined

preUpdate(step) → {undefined}

This method is activated before the object's main update loop and ensures that the object is ready for the update. The purpose is to protect certain processes from being disabled when overriding the main update loop. This method can also be overridden, but it should be done with caution.
Parameters:
Name Type Description
step number Fixed time step.
Source:
Returns:
Type
undefined

toString() → {string}

Returns a string representation of the hitbox. Useful for troubleshooting.
Overrides:
Source:
Returns:
Type
string

update(step) → {undefined}

Override this method to update your interactive object's position and appearance.
Parameters:
Name Type Description
step number Fixed time step.
Source:
Returns:
Type
undefined