Cocos Creator API

0.7.1

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

Vec2

Extends ValueType
Module: cc

Representation of 2D vectors and points.

see Unknown

Properties

ONE Vec2 static

return a Vec2 object with x = 1 and y = 1

ZERO Vec2 static

return a Vec2 object with x = 0 and y = 0

up Vec2 static

return a Vec2 object with x = 0 and y = 1

RIGHT Vec2 static

return a Vec2 object with x = 1 and y = 0

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Methods

Vec2
(
  • [x =0]
  • [y =0]
)

Constructor

name type description
x optional number 0
y optional number 0

clone ( ) Vec2

clone a Vec2 value

returns:

type: Vec2

set
(
  • newValue
)
Vec2

name type description
newValue Vec2

!#en new value to set. !#zh 要设置的新值

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

returns this

equals
(
  • other
)
Boolean

name type description
other Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Boolean

toString ( ) string

returns:

type: string

lerp
(
  • to
  • ratio
  • [out ]
)
Vec2

name type description
to Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0
ratio number

the interpolation coefficient

out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

addSelf
(
  • vector
)
Vec2

Adds this vector. If you want to save result to another vector, use add() instead.

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

returns this

add
(
  • vector
  • [out ]
)
Vec2

Adds two vectors, and returns the new result.

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0
out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

the result

subSelf
(
  • vector
)
Vec2

Subtracts one vector from this. If you want to save result to another vector, use sub() instead.

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

returns this

sub
(
  • vector
  • [out ]
)
Vec2

Subtracts one vector from this, and returns the new result.

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0
out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

the result

mulSelf
(
  • num
)
Vec2

Multiplies this by a number. If you want to save result to another vector, use mul() instead.

name type description
num number

returns:

type: Vec2

returns this

mul
(
  • num
  • [out ]
)
Vec2

Multiplies by a number, and returns the new result.

name type description
num number
out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

the result

scaleSelf
(
  • vector
)
Vec2

Multiplies two vectors.

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

returns this

scale
(
  • vector
  • [out ]
)
Vec2

Multiplies two vectors, and returns the new result.

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0
out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

the result

divSelf
(
  • vector
)
Vec2

Divides by a number. If you want to save result to another vector, use div() instead.

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

returns this

div
(
  • vector
  • [out ]
)
Vec2

Divides by a number, and returns the new result.

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0
out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

the result

negSelf ( ) Vec2

Negates the components. If you want to save result to another vector, use neg() instead.

returns:

type: Vec2

returns this

neg
(
  • [out ]
)
Vec2

Negates the components, and returns the new result.

name type description
out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

the result

dot
(
  • [vector ]
)
number

Dot product

name type description
vector optional Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: number

the result

cross
(
  • [vector ]
)
number

Cross product

name type description
vector optional Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: number

the result

mag ( ) number

Returns the length of this vector.

returns:

type: number

the result

magSqr ( ) number

Returns the squared length of this vector.

returns:

type: number

the result

normalizeSelf ( ) Vec2

Make the length of this vector to 1.

returns:

type: Vec2

returns this

normalize
(
  • [out ]
)
Vec2

Returns this vector with a magnitude of 1.

Note that the current vector is unchanged and a new normalized vector is returned. If you want to normalize the current vector, use normalizeSelf function.

name type description
out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

result

angle
(
  • vector
)
number

Get angle in radian between this and vector

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: number

from 0 to Math.PI

signAngle
(
  • vector
)
number

Get angle in radian between this and vector with direction

name type description
vector Vec2

Constructor

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: number

from -MathPI to Math.PI

rotate
(
  • radians
  • [out ]
)
Vec2

rotate

name type description
radians number
out optional Vec2

optional, the receiving vector

  • x number optional , default: 0
  • y number optional , default: 0

returns:

type: Vec2

the result

rotateSelf
(
  • radians
)
Vec2

rotate self

name type description
radians number

returns:

type: Vec2

returns this

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index