Beding/warping Sprites by bezier

OK, its not the best, there are a lot of improvements could be done (like batching or inherit from CCSprite, using linear creates not nice results, etc) but so far this is what I have.
If anyone wants to improve the class or tell me what could be implemented or extended, please tell me, I will try to help.

extras:

  • setTexture - replaces texture
  • setStrokeScale - keeps the size and position of nodes, but the texture size is scaled

TexturedSpline parameters:
- a vector of Vec2 points ( the path)
- the amount of subdivisions between point and point
- the texture or texture name
- the type of spline (Linear, catmull-rom**, b-qubic) (** = default)

And this is an expample of usage

if(auto spline = TexturedSpline::create(path, 10, "brick.jpg")
{
    addChild(spline);
    spline->setPosition(center);
}

TexturedSpline.cpp (11.0 KB)
TexturedSpline.h (2.6 KB)

notes:
the path must contain 4 POINTS or more
If the points distance is bigger than the sprite size then it repeats the sprite.

  • This requires the texture’s dimensions to be pow of 2.
  • so: If u want to just distort any image, remove that requiremente from code and texture will not be repeated, by doing this the texture wont repeat (AFAIK, I actually havent tried)
4 Likes