Coin-coin le Canapin's Forum Posts

  • You can compare the enemy position with the main character position on the X axis.

  • I measured the duration of each event using wallclocktime function and clicking like mad, and it appears that the first algorithm is faster.

    0.12s vs 0.15s, the results are constant over my tries.

  • I used wallclocktime and it worked perfectly

    What I'm trying to achieve is a destructible terrain "à la Worms", which counts how much pixels were destroyed in order to generate a proper number of particles.

    I first used a loop using "Canvas.alphaAt(X,Y)" for each pixel contained in the radius of the explosion, but r0j0hound suggested that I could store all the Canvas pixels in an array, and iterate over the array because it would be faster.

    That's what I did and it is indeed faster. I first look at all the pixels contained in the explosion radius. For each pixel, I look at its transparency. If its alpha ≠ 0, then I increases the particle quantity variable then I update my array to replace this pixel with a transparent one.

    So this is this step which is slow, but I don't see how I could optimize this, I need to update all these specific pixels in the array, because I compare my collisions with the pixels contained in the array, not with the pixels currently drawn in my canvas (because it's slower).

    I made a thread about this project :

    The elements have to be updated at once, because in my final game, more than 2 projectiles could hit the landscape quickly in the same area.

    chrisinfinger > Because I only update pixels that were not transparent, I think it already works as a filter, sort of. Am I right ?

  • Hi. I have an event which take some times : like updating thousands of entries in an array. When the event is executed, the computer seems to freeze for a short time.

    Is it possible to know precisely how much time this event takes ?

  • Hi again,

    I used a faster algorithm based on http://www.wikiwand.com/en/Midpoint_circle_algorithm to browse all the pixels contained in the radius of each explosion.

    It's still kind of slow for large radius > 50.

    I'm even not sure there is a noticeable difference :/

    fast algorithm : http://canapin.com/construct/worms/terrain/

    slow algorithm : http://canapin.com/construct/worms/terrain_slow/

    (to be sure the first one is properly updated, clear the cache of this URL : http://canapin.com/construct/worms/terrain/c2runtime.js , ctrl-F5 on Chrome)

    The first seems to be a litter faster than the other one. Anyone notices the same or I just want to believe too much ?

    The slow things is updating all the pixels of the radius explosion in the array and I dont know how I can increase performances for this.

  • korbaach I like the graphics very much

  • I'm pretty sure there is a nicer way to do it, but it works

    It also prevents the sprites to go outside the window on the left and right.

    Edit : sorry, I updaded the wrong file, here is the new and working one !

  • Thank you for your reply

  • Something like this ?

  • Hi.

    I was trying to draw a filled circle using this algorithm : http://stackoverflow.com/a/1201304

    I am aware it's certainly possible to draw a filled circle using simpler way, but I'm trying to find a fast algorithm to iterate all the pixels contained in a circle, so I'm trying things.

    [attachment=1:2zbix766]disk2.png[/attachment:2zbix766]

    [attachment=2:2zbix766]disk.png[/attachment:2zbix766]

    The question is : why doesn't Canvas draw full black lines here ? The "grey" here is like 25% opacity, it should not be transparent in any way, just plain black.

  • Basically, you can't.

    If you really want to, you can check this message : destroy-objects-parts_p636126?#p636126 <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    For my game, I'll have to create custom movements from A to Z because of the Canvas landscape and I bet it won't be easy.

    Regarding my algorithm, I'm using the one written in the second comment : http://stackoverflow.com/questions/1201 ... ed-circles

    That's not very fast. I'll try to use the first one (I tried before but I was using it wrong so the results weren't as expected...).

    I know nothing about maths so it's kinda hard for me to use all this stuff with numbers, letters and sometimes more. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    I also saw the 1*1 tilemap solution.

    If you simply want to create a hole in a picture with no more effects like your tank game, the Canvas plugin itself can do that very well, just paste any sprite on your canvas with a "Destination out" blend effect.

    It's very efficient and I think even with big holes. But maybe you've already tried this ?

    My project is slower more complicated because I really want to count each pixel in order to have a proportional number of particles.

    I need to use a faster algorith to count the pixels inside the explosion radius, and I'd also like to find a faster way to update my array, I don't know if it is possible.

    BTW, I've also added an increasing/decreasing radius option with the mousewheel as you did, so you can see the actual (bad) performances with more pixels to remove : http://canapin.com/construct/worms/terrain/

    Also, my canvas is quite small. I bet the performances decreases a lot with a bigger canvas.

    Edit : well, they don't. Takes some time to put all the pixels into the array, thought.

  • I dont really understand what kind of advices or feedbacks you want here ^^"

    For example, like this !

    Alhough, what about the particles being of the color of the pixel destroyed? That should be a bit better ^^

    And technical advices too.

    humanescape : thanks

  • Hi. I'm working on a game like Worms.

    I made a destructible landscape you can destroy pixel by pixel, with the help of the Canvas plugin (and the precious advices of R0J0hound).

    This is quite easy ; the tricky part was that I wanted to have a number of generated particles according to the number of destroyed pixels.

    I'm storing all my landscape pixels in an array. Then I check the pixels directly into the array instead of checking them directly on the canvas via the alphaAt method. Finally I update the array to remove all the pixels that were destroyed.

    It still needs tweaks to be faster.

    http://canapin.com/construct/worms/terrain/

    I'm interested in any advice or idea ! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Hi again.

    I've used an array as you said to read pixel informations. It's much faster !

    Now i just have to update the array, replacing all pixels from the hole by transparent pixels (a few thousand).

    Hope this won't be too CPU expensive.