2
\$\begingroup\$

I'm developing a 2D game using Cocos2d-x. Is possible to use CCBezierTo to parameterize a sine function?

\$\endgroup\$
  • \$\begingroup\$ I guess you're talking about a sine function? What do you mean when you say use a bezier curve to parametrize a sine function? What are you trying to achieve? \$\endgroup\$ – bummzack Jul 13 '12 at 7:36
  • \$\begingroup\$ Make a semi-period, concave or convex. My idea is create a sine, with use function sin, just using curves chained. \$\endgroup\$ – vgonisanz Jul 13 '12 at 7:38
  • \$\begingroup\$ So in the end you want a bezier curve, that matches a sine curve? So that you can use it with CCBezierTo. Is that right? \$\endgroup\$ – bummzack Jul 13 '12 at 7:41
  • \$\begingroup\$ Yes, it is right. I must not be exactly a sine, because i'm interesting in create a method to make trajectories beautiful. My random experiments with bezier are horrible. Learning to make a sine, it would help me to create more things. \$\endgroup\$ – vgonisanz Jul 13 '12 at 7:44
  • 1
    \$\begingroup\$ Theoretically, writing a the sin function in terms of polynomials (especially finite series) is mathematically impossible since the basis (be it Bernstein polynomials or your 1,x,,x^2,etc.. canonical one) is finite and cannot reproduce the taylor series of the sine function. You may find it faster to just use a truncated Taylor expansion of the sine. But if you aim to "draw" something, you can for sure mimic the images of some simple non-linear functions. (I wrote this comment just for the mathematical caveat.. no trolling intended :D). \$\endgroup\$ – teodron Jul 13 '12 at 8:28
2
\$\begingroup\$

Just use Bezier, giving 3 points in concave section, and another 3 in convex section, its easier than give all points to do a perfect sine, and the trajectory is the same.

\$\endgroup\$
3
\$\begingroup\$

You could create a Bézier curve that matches a sine (read this article for an example). Creating a Bézier curve from a sine, just to feed into CCBezierTo seems like a very counter-intuitive way of doing things though.

I would skip CCBezierTo entirely and update the position of your sprite yourself. You could do so in your update method or implement a CCAction yourself. The easiest form of movement would be to increase x constantly (or with a decaying value to simulate some sort of drag) and use the sine function to calculate y.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.