Kiwi.Components.Input Class
The Input Component is used on GameObjects in which the user may interactive with via a Mouse or Touch and as such this class contains useful methods and callbacks you can subscribe to. By default the Input component is disabled (this is because when enabled the input component can be process intensive) but you can enabled it yourself (which is recommened) BUT in case you forget the input component will automagically be enabled once you access a Signal on this class.
Constructor
Kiwi.Components.Input
-
owner
-
box
-
[enabled=false]
Parameters:
-
owner
ObjectThe Object that this Component is on. Generally this will be a Entity.
-
box
Kiwi.Components.BoxThe box which contains the worldHitbox that is to be used for the event firing.
-
[enabled=false]
Boolean optionalIf this input component should be enabled or not.
Returns:
Item Index
Methods
Properties
- _box
- _distance
- _dragDistance
- _dragEnabled
- _dragSnapToCenter
- _enabled
- _isDown
- _isDragging
- _isUp
- _justEntered
- _nowDown
- _nowDragging
- _nowEntered
- _nowLeft
- _nowUp
- _onDown
- _onDragStarted
- _onDragStopped
- _onEntered
- _onLeft
- _onUp
- _outsideBounds
- _tempCircle
- _tempDragDisabled
- _tempPoint
- _withinBounds
- active
- dirty deprecated
- dragDistance
- enabled
- game
- isDown
- isDragging
- isUp
- name
- onDown
- onDragStarted
- onDragStopped
- onEntered
- onLeft
- onPress
- onRelease
- onUp
- outsideBounds
- owner
- state
- withinBounds
Methods
_evaluateMousePointer
-
pointer
Evaluates where and what the mouse cursor is doing in relation to this box. Needs a little bit more love.
Parameters:
-
pointer
Kiwi.Input.MouseCursor
_evaluateTouchPointer
-
pointer
A private method for checking to see if a touch pointer should activate any events.
Parameters:
-
pointer
Kiwi.Input.FingerThe pointer you are checking against.
_updateMouse
()
private
The update loop that runs when the mouse manager is the method for interacting with the screen.
_updateTouch
()
private
The update loop that gets executed when the game is using the touch manager.
destory
()
public
Destroys the input.
destroy
()
public
Destroys this component and all of the properties that exist on it.
disableDrag
()
public
Disables the dragging of this entity.
enableDrag
-
[snapToCenter=false]
-
[distance=1]
Enables the dragging of this entity.
Parameters:
-
[snapToCenter=false]
Boolean optionalIf when dragging the Entity should snap to the center of the pointer.
-
[distance=1]
Number optionalIf when dragging the Entity should snap to numbers divisible by this amount.
objType
()
String
public
The type of object this input is.
Returns:
"Input"
postUpdate
()
public
Components can postUpdate, that is run an update after the parent has updated. This is to be overriden by subclasses.
preUpdate
()
public
Components can preUpdate, that is update before the parent updates. This is to be overriden by subclasses.
update
()
protected
The update loop for the input.
Properties
_distance
Kiwi.Geom.Point
private
The distance between the top left corner of this Objects parent and the coordinates of a Pointer.
_dragDistance
Number
private
This is used while dragging so that you can make the IChild 'snap' to specific numbers to give a 'grid like' effect. E.g. If you had a 32 by 32 grid down and you wanted to make an element draggable but snap to the grid you can set this to 32. Default value is one.
Default: 1
_dragEnabled
Boolean
private
Indicates if dragging is currently enabled.
Default: false
_dragSnapToCenter
Boolean
private
If when dragging, the IChild should snap to the center of the pointer it is being dragged by.
Default: false
_enabled
Boolean
private
If this input is enabled or not.
Default: false
_isDown
Kiwi.Input.Pointer
private
If a pointer is current pressing down on the input, this will be a reference to that pointer. Otherwise it will be null.
_isDragging
Kiwi.Input.Pointer
private
A reference to the pointer that is currently 'dragging' this Object. If not dragging then this is null.
Default: null
_isUp
Boolean
private
A boolean that indicates if no pointer is currently on the pointer
Default: true
_justEntered
Boolean
private
If a pointer just entered the input. Used for mouse's to indicate when to appropriately fire the down event. Note: Could be removed once mouse version of update gets updated.
Default: false
_nowDown
Kiwi.Input.Pointer
private
Temporary property that gets updated everyframe with the pointer that is currently 'down' on this entity.
Default: null
_nowDragging
Kiwi.Input.Pointer
private
Temporary property of the pointer that just started draggging the entity.
Default: null
_nowEntered
Kiwi.Input.Pointer
private
Temporary property of the pointer that is now within the bounds of the entity
Default: null
_nowLeft
Kiwi.Input.Pointer
private
Temporary property of the pointer that just left the bounds of the entity.
Default: null
_nowUp
Kiwi.Input.Pointer
private
Temporary property that gets updated everyframe with the pointer that was just 'released' from being down on this entity
Default: null
_onDown
Kiwi.Signal
private
Kiwi Signal for firing callbacks when a pointer is active and has pressed down on the entity.
_onDragStopped
Kiwi.Signal
private
Kiwi Signal for firing callbacks a entity stops being dragged. Like on release.
_onEntered
Kiwi.Signal
private
Kiwi Signal for firing callbacks when a pointer is active and has entered the entities hitbox.
_onLeft
Kiwi.Signal
private
Kiwi Signal for firing callbacks when a pointer is active and has left the entities hit box.
_onUp
Kiwi.Signal
private
Kiwi Signal for firing callbacks when a pointer just released from either being above the entity or the pointer was initally pressed on it.
_outsideBounds
Boolean
private
boolean indicating if every pointer is currently outside of the bounds.
Default: true
_tempCircle
Kiwi.Geom.Circle
private
A Temporary Circle object which is used whilst checking to see if there is any overlap.
_tempDragDisabled
Boolean
private
A boolean indicating if dragging is temporarly disabled. Internal use only to stop events from misfiring.
_tempPoint
Kiwi.Geom.Point
private
A Temporary Point object which is used whilst checking to see if there is any overlap.
_withinBounds
Kiwi.Input.Pointer
private
Indicates if a pointer is within the bounds or not. If one is then it referers to the pointer that is. Other it will be null.
active
Boolean
public
An active Component is one that has its update method called by its parent.
Default: true
dirty
Boolean
deprecated
public
The state of this component.
Default: false
dragDistance
Number
public
The drag distance that is used when dragging this object. See _dragDistance for more information.
enabled
Boolean
public
Get if the input is enabled or not. Note: Inputs should only be enabled when needed, otherwise unnecessary processing does occur which can result in a slower game.
isDown
Boolean
public
Used to see if a pointer is currently on this input. Returns a boolean indicating either true or false. This is READ ONLY.
isDragging
Boolean
public
Returns a boolean indicating if this is currently dragging something. This is READ ONLY.
isUp
Boolean
public
Used to see if no pointer is on this input (so it is up). This is READ ONLY.
name
String
public
The name of this component.
onDown
Kiwi.Signal
public
Returns the onDown Signal, that fires events when a pointer is pressed within the bounds of the signal. Note: Accessing this signal enables the input. This is READ ONLY.
onEntered
Kiwi.Signal
public
Returns the onEntered Signal, that fires events when a pointer enters the hitbox of a entity. Note: Accessing this signal enables the input. This is READ ONLY.
onLeft
Kiwi.Signal
public
Returns the onLeft Signal, that fires events when a pointer leaves the hitbox of a entity. Note: Accessing this signal enables the input. This is READ ONLY.
onUp
Kiwi.Signal
public
Returns the onUp Signal, that fires events when a pointer is released either within the bounds or was pressed initially within the bounds.. Note: Accessing this signal enables the input. This is READ ONLY.
outsideBounds
Boolean
public
See if no pointers are within the bounds of this entity. This is READ ONLY.
owner
Object
public
The object that owns this entity
withinBounds
Boolean
public
Check to see if any pointer is within the bounds of this input. This is READ ONLY.