0 Favourites

Solid attribute: how to avoid it to keep high performance?

This forum is currently in read-only mode.
  • I'm running through a really noobish issue and I'm digging the forum since hours without finding a solution to my problem

    I always thought that you had to put the attribute "solid" to an object if you dont want your character to overlap or go through it and it worked... until I put hundred of objects with the solid attributes in a big layout and it drops horribly the performance.

    So I guess it's not the right way to doing it but I can not find another way.

    Say, as an example, that my character is a space ship with the 8-direction behaviour and it is flying through asteroids field = how can I make those asteroids "solid"... without using the solid attribute ?

    Thank you so much for your help, there's something I'm missing here!

    // izioq //

    P.S: the "bounce" event of the 8-direction behaviour is not a good answer... because it makes the player "bounce" and not stop, like with the solid attribute...

  • Making them solid is not the problem.

    To many collissions checks / tick will bring performance to its knee's.

    First a little explination. If you write a line of code in Construct, that is not actualy the code. Each line of code in construct is in fact a little program. So, if you write 'on coliision with astroids', you wrote a program that loops trough each astroid and checks if it collides with your ship. And thats a heavy calculation, for ALL hundreds of astroids.

    To keep this under control you must include less asteroids in the calculations. One way to do this is ... with 'pick nearest'. A condition 'pick nearest astroid to the ships position' combined with (and in that order) a condition 'is colliding with ship'. If the asteroids are to close to each other, this will miss some collisions. But is blazing fast.

    An other way is to 'pick by comparisation'. Expression = distance (astroid.x,astroid.y,ship.x,ship.y) .. object is astroids ... value is lets say 150 (depending on the size of you layout). Combine that again with the 'on collision with'

    What happens is ... it again will loop trough all astroids to test that distance, but without checking collision. And that is a speedy calculation. Now it picks all astroids that are 150 pixels away from ship. All the others are not picked. And the collission condition will only check those (close) asteroids for collisions.

  • Thanks for your reply!... but :

    1/ after writing the "'pick nearest astroid to the ships position' combined with (and in that order) a condition 'is colliding with ship'" what is the "then" that I should write in order to prevent the ship to pass through the asteroid ?

    2/ I'm pretty sure (I've read it somewhere in old posts here) that a lots of solid objects could drop performance drasticly: and when I unchecked it, everything runs fine. But there must be a trick somewhere ? Like, if I'm doing a platformer with a huge level and many blocks that should be solid in order to let the player walk on them, how am I supposed to do so?

    [EDIT]

    it's definitely a "solid" attribute issue because when I unchecked it, everything is smooth with good performance even if (as you said) " on coliision with astroids', you wrote a program that loops trough each astroid and checks if it collides with your ship. And thats a heavy calculation, for ALL hundreds of astroids. "

    I'm stuck there...

  • Do you need to have hundreds of asteroids present all at once?

    Maybe you can "destroy" them if they are too far from the viewport, and re-create them when the player gets closer.

    If they don't need to have exact persistence in location, this can be pretty easily done by randomly creating asteroids at coordinates that are beyond the viewport... but if they need to have exact persistence you will need to store coordinates in an array or similar manner - or use seeded random generation (there are some seeded random plugins still for CC somewhere) so that you can "randomly" place them back into existence.

    Knowing a little more about the importance of the application of your idea would help understand what exactly needs to be achieved

    ~Sol

  • Thanks SoldjahBoy !

    I'll post a cap later when I'll be at home.

    In fact I've talked about a spaceship and asteroids just as an example but it is a bad one because asteroids could be random. But what if, for intance, I want to make a platformer with a lot of single blocks everywhere in a big layout and the player has to jump from one to another, horizontaly, verticaly, to navigate all around the layout to collect keys (for example) etc. = so I need a "fixed" and designed level (not a random) with my keys, enemies, etc. on precise location, etc... but if I put blocks with the solid attribute everywhere, the game will be horribly slow and have lags... how can I manage to make solid blocks with this example ?

    Again : I'll post a cap later but maybe you get a better idea of the application of my idea with the platformer example ?

    Thanks again, cheers !

    // izioq //

  • If you have platforms for example, especially static ones that don't move, you can store each platform coordinates either in an array, or with a placeholder object (sensor/mask/detector) that isn't "solid" and create the platform in it's place with solid attribute if it's on-screen or within X amount of pixels of screen boundary.

    Loads of persistent AND moving objects becomes quickly a challenge - but each scenario would be unique as to how you could go about making is optimised.

    I haven't actually used CC in, well, years... but it's burned into my brain like breathing and existing... so I'm sure I can at least make some suggestions which way would be a good solution to try.

    *EDIT*

    Another way you can do platforms is to have simply one larger "mask" graphics (opacity set to 0 so you can't see it - but it still exists in the game) which has "solid" behaviour - but can be stretched out to cover several of your smaller "blocks" that make up your tile sets. For example you can have a platform made from 10 blocks in length, but only 1 mask object that stretches to cover all 10 of the smaller objects - thus using only 1 solid object for collision, leaving your 10 blocks as the cosmetic only appeal.

    ~Sol

  • Your solution with a larger "invisible" mask sounds like a good solution to try, thanks!

    But to improve myself I would be really glad to know more about your array solution as I don't understand now how arrays work.

    So here is a link to DL a simple cap (because of my limited account you'll have to add the https : // before) = drive.google.com/open?id=0B3YMYyFd_M6dQURiWDJURjdWU1E

    If it's not too much to asked it would be very cool if you could implement your array solution in this cap and send it back

    (in this cap there is no lag or drop performance because I've really just add the blocks with nothing else)

    Thank you so much in advance mate!

    // izioq //

  • I don't think I even have CC installed anymore - I haven't used it in *years*

    However - here is an old CC cap file (link still is active/works, amazingly - after all these years) to a "map generator" using an array. Maybe you can learn more about how arrays work from studying THIS

    *EDIT*

    You may also want to check THIS as well

    ~Sol

  • Thank you very much, I'll check that asap

    Have a good day!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Good luck!

    Let me know if you get stuck, I'll see if I can point you further to more help/examples

    ~Sol

  • Excuse me my stupidity for not seeing that this is a post in 'Classic'.

    Question. Does this lags ?

    https://www.dropbox.com/s/tg4gxdd1zvado ... s.cap?dl=0

  • SoldjahBoy I'll do mate !

    @99Instances2Go : many thanks for taking the time to creatre a cap, that's cool! Unfortunatly it doesnt work because the blocks still have the "solid" attributes and that's what drop the performance down. But thanks again!

    // izioq //

  • Thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
331 35,573
Lordshiva1948's avatar
Lordshiva1948
Unread hot topic
157 12,693
megatronx's avatar
megatronx
Unread hot topic Locked topic
112 7,122
Ashley's avatar
Ashley Construct Team Founder