jamesalone jamesalone - 16 days ago 5
Javascript Question

Cocos2D JS Vec2 is undefined

I've been trying to use Vec2 for a while with no luck, I got error message such as Vec2 is undefined, Vec2 is not a function, etc.

Code I've tried:

var point = Vec2(100,100);


var point = cc.math.Vec2(100,100);


Is there anything else I'm missing? It seems that the documentation for Cocos2D JS is not up to date.

Answer

I have never used Vec2 in js so I do not know explicitly what is happening with that but you can use cc.p(x,y)

Example:

var point = cc.p(100, 100); cc.log(point.x) -> 100