API Documentation

for 0.0.1
Show:

Touch Class

Touch give an interface to access the multitouch events of the device. It holds a list of currently active touches and various ways to access their coordinates.

Constructor

Touch

(
  • params
)

Parameters:

  • params Object

    Config parameters

    • target DOMElement

      The DOM element that will be used to attach touch events on

Example:

//this is how to use events in a user's script
function script()
{

   var M;
   var R;

   var camera;
   var cube;
   var light;

   var y = 0;
   var speed = 0;

   var touch;

   this.setup = function()
   {
       M = this.getContext();
       R = M.addComponent( new Mobilizing.Renderer3D() );

       touch = M.addComponent(new Mobilizing.input.Touch({"target": R.canvas}));
       touch.setup();//set it up
       touch.on();//active it

       //construct a default perspective camera
       camera = new Mobilizing.Camera();
       camera.setFarPlane(10000);
       camera.setToPixel();
       R.addCamera(camera);

       //make a light
       light = new Mobilizing.Light();
       light.transform.setLocalPosition(500,-100,500);
       light.setDistance(5000);
       R.addToCurrentScene(light);

       //make a cube
       cube = new Mobilizing.Mesh({primitive:"box", width:1, height:1, depth:1});
       cube.transform.setLocalPosition(0,0,0);
       cube.transform.setLocalScale(50);
       R.addToCurrentScene(cube);
   };

   this.update = function()
   {
       if(touch.pressed){

           cube.transform.setLocalPosition(
                touch.getX(0),
               - touch.getY(0),
               0);
       }
   };

};

Methods

byPass TODO!

()

chain

(
  • component
)
Adds a component to this chained component array

Parameters:

get

(
  • index
)
TouchObject

returns a TouchObject

Parameters:

  • index Number:Int

    the index of the touchObject to get

Returns:

getChainedComponents

() Array
Returns the array of attached children components

Returns:

Array: children arrays

getContext

() Context

Inherited from Base but overwritten in src/js/Mobilizing/Base.js:37

Get the Mobilizing context

Returns:

Context: The Mobilizing context

getDelta

(
  • index
)
Object

Returns an object {x:Number, y:Number} that represents the coordinate of the touch delta, that is the numerical difference between the previous state in time and the actual one.

Parameters:

  • index Number:Int | | Object:Touch

    the index of the touch to get coordinates from, or the touch object

Returns:

Object:

{x:Number, y:Number}, the x & y coordinates of the touch delta;

getDeltaX

(
  • index
)
Number:Int

Returns a Number that represents the coordinate of the touch delta, that is the numerical difference between the previous state in time and the actual one.

Parameters:

  • index Number:Int | | Object:Touch

    the index of the touch to get x coordinate from, or the touch object

Returns:

Number:Int:

, the x coordinates of the touch delta;

getDeltaY

(
  • index
)
Number:Int

Returns a Number that represents the coordinate of the touch delta, that is the numerical difference between the previous state in time and the actual one.

Parameters:

  • index Number:Int | | Object:Touch

    the index of the touch to get y coordinate from, or the touch object

Returns:

Number:Int:

, the y coordinates of the touch delta;

getID

() Int
Get the Object unique ID

Returns:

Int: The Object ID

getOffset

(
  • index
)
Object

Returns an object {x:Number, y:Number} that represents the coordinate of the touch offset, that is the numerical difference between the start point of the touch and the actual one.

Parameters:

  • index Number:Int | | Object:Touch

    the index of the touch to get offset coordinate from, or the touch object

Returns:

Object:

{x:Number, y:Number}, the x & y coordinates of the touch offset;

getOffsetX

(
  • index
)
Number

Returns a Number that represents the x coordinate of the touch offset, that is the numerical difference between the start point of the touch and the actual one.

Parameters:

  • index Number:Int | | Object:Touch

    the index of the touch to get x offset coordinate from, or the touch object

Returns:

Number:

the x coordinates of the touch offset;

getOffsetY

(
  • index
)
Number

Returns a Number that represents the y coordinate of the touch offset, that is the numerical difference between the start point of the touch and the actual one.

Parameters:

  • index Number:Int | | Object:Touch

    the index of the touch to get y offset coordinate from, or the touch object

Returns:

Number:

the y coordinates of the touch offset;

getPinch

() Number

Returns a Number that represents the pinch touch move, that is the numerical difference between the start point of 2 touches and the actual one.

Returns:

Number:

the pinch delta value;

getStatus

() Boolean
Get the activation status of the component

Returns:

Boolean: True if active, false otherwise

getX

(
  • index
)
Number:Int

returns the x coordinate of the touch given as paramater

Parameters:

  • index Number:Int

    the index of the touch to get x coordinate from

Returns:

Number:Int:

x coordinate of the touch if active, -1 if not active

getY

(
  • index
)
Number:Int

returns the y coordinate of the touch given as paramater

Parameters:

  • index Number:Int

    the index of the touch to get y coordinate from

Returns:

Number:Int:

y coordinate of the touch if active, -1 if not active

off

()
Deactivate the component

on

()
Activate the component A call to this method calls the setup method if it has not been run yet

onTouchEnd

() private

onTouchEnd listener

Manage a touch removal and organize it in the main touch list Input.touches

onTouchMove

() private

onTouchMove listener

Manage a touch move and organize it in the main touch list Input.touches

onTouchStart

() private

onTouchStart listener Manage a new touch and organize it in the main touch list Input.touches

postUpdate

()
Run code after the update of all components is run This empty method is usually overriden to perform post-update actions for the component It is called periodically by an internal Mobilizing mechanism

preLoad

()
preLoad the component This empty method is usually overriden to perform setup actions for the component. The preLoad is designed to be called before any other method, even setup. In the case of user scripts, it is used to preload all needed datas before the setup (pictures, font, etc.) It is called automatically by an internal Mobilizing mechanism and should thus not be called directly

preUpdate

()
Run code before the update of all components is run This empty method is usually overriden to perform pre-update actions for the component It is called once per component by an internal Mobilizing mechanism

runSetup

()
Calls the setup if it has not already been called This method should not be called This is where all the initialization (such as adding event listeners)should be done It is called automatically by an internal Mobilizing mechanism and should thus not be called directly

setContext

(
  • context
)
Set the Mobilizing context

Parameters:

  • context Context
    The Mobilizing Context

setName

(
  • name
)
Set the Object name

Parameters:

  • name String
    The Object name

setup

()
Set's up the component This empty method is usually overriden to perform setup actions for the component This is where all the initialization (such as adding event listeners)should be done It is called automatically by an internal Mobilizing mechanism and should thus not be called directly

setup Setup

()

Initialization method

update

()

Inherited from Component but overwritten in src/js/Mobilizing/input/Touch.js:299

Properties

_active

Boolean private
Whether the component is active or not

_context

Context private
A reference to the Mobilizing context

_setupDone

Boolean private
Whether the component's setup has been called

count

Number

Gives the number of touch currently active

events

EventEmitter
An event emmiter used to send custom events

pressed

Boolean

true if the active touch on screen > 1, false otherwise