CCPoint questions

CCPoint questions
0.0 0


Hi all,

I’m pretty new to Cocos2d-x but finding it very cool to work (and play) with.

I had several questions related to CCPoint, so I thought I’d ask here.

1 - From what I understood, CCPoint can be used as a “Vector” class (and also using ccAdd, ccMult, etc to do the math)
2 - If the above is correct, is there a way to “limit” the magnitude of a vector or do we have to implement this?

Thanks for your help


Limit it as in make sure it’s always the same length?

I think you’d just have to normalize it and scale it by the desired length any time it changes.



I came up with something like that:
1 - check squared length of “target” vector
2 - if (squared length) is greater than the max*max (max is the value I want to limit to)
normalize and “multiply” by max value