Rewrite the ProgressTimer of cocos2d to realize the Radial progress bar of any starting point

Explain what to do:

The progress starting point of the native ProgressTimer control can only be at (0.5, 1), as follows:

We want to change it to any point on the side of the rectangle as the starting point, as follows: 

 Let me talk about the logic of drawing first:

First calculate the vector after the rotation to a certain angle according to the starting point vector, and then calculate the rectangle vertices passed during the rotation process, and connect the starting point, end point and rectangle vertices with the rotation center point (point 0 in the figure below) to form one by one Adjacent triangles, just paint these triangles with the texture color. as follows:

 

  •  Changed CCProgressTimer.h and CCProgressTimer.cpp can be downloaded directly.
  • Let's analyze several technical points that need to be mastered in the implementation process:
    1. Find the vector after a vector is rotated by a certain angle, (two-dimensional rotation matrix)
    2. Ray Intersection Algorithm
    3. Usage of OpenGL's vertex buffer VBO and index buffer EBO in cocos
    4. According to the coordinates of a certain point in the Sprite local coordinate system, how to calculate the vertex coordinates and texture coordinates of this point

Guess you like

Origin blog.csdn.net/u012861978/article/details/131292883