Search code examples
javascripthtmlcocos2d-js

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.


Solution

  • 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