I'm currently trying to develop a game using Cocos2d-x using C++. I really need to generate this burst or (donut-shaped) pulse. I'm having a difficult time how to generate such shape.

At first, I was thinking of scaling the image but that didn't work out because the line or "diameter" of the donut shape gets bigger accordingly. Any experienced coders who can provide an equation of this thing? or maybe "mathematics" is more exact.

c++ code sample


  • 1
    $\begingroup$ It seems you have the answer you need, but if you ever want to look up the mathematics for anything else, the 2d donut-like shape you describe is called an annulus $\endgroup$ – trichoplax Apr 30 '16 at 1:21
  • 1
    $\begingroup$ Please don't post screenshots of code. It's not searchable and it prevents other people pasting your code into their own editor to test it. $\endgroup$ – Dan Hulme Apr 28 '17 at 8:16

Rather than using an image, I would suggest doing this kind of effect using a shader. I'm not familiar with Cocos2d-x, but some quick googling suggests that it can work with shaders. You'd use a pixel shader that calculates the distance of each pixel to the center of the pulse effect, then applies a function based on that distance to define the shape and appearance of the pulse.

I made a quick shadertoy as a proof of concept and example.

enter image description here

  • $\begingroup$ Hey thanks a lot for sharing ur knowledge. I wrote a code but it seems to have some error ive edites the post with an image. I would appreciate if u cab give me help with that. Im constantly running into problems so i searched for ur contact number cuz i cant post image in a comment lol. $\endgroup$ – quinnavery May 4 '16 at 10:24
  • 1
    $\begingroup$ @quinnavery ...did you just copy/paste the shadertoy into your code? :D You're going to need a bit more plumbing than that. It's written in GLSL, not C++, which is where most of the errors are coming from. If you're not familiar with using shaders in Cocos2d-x, you should look up some tutorials on the subject first, such as this one. $\endgroup$ – Nathan Reed May 4 '16 at 16:17
  • $\begingroup$ hi, Im having some trouble with my developer.... he really doesnt know how to code (Just my opinion) I'm considering to hire somebody else to create the game for me. You really seem like you can code since u shared your knowledge in less than a day. I think it will be quite easy for you? ^^ I'm trying to create for android platform and dont mind what program u use cocos, unity...., Will you be interested? I do pay upfront LOL $\endgroup$ – quinnavery May 8 '16 at 17:03
  • $\begingroup$ if u are interested, plz let me know and we can proceed to further negotiations via email or something. I can pay you via paypal just to let ya know~ $\endgroup$ – quinnavery May 8 '16 at 17:10

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.