Sprite is overlaping or distance expression?

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • Just curious whats faster to calculate.

    Let's say there's a 10 sprites "A" (container with "detector" sprite) and one sprite "B".

    1.Every time "B" overlaps sprite "A" "detector" (one or few), "A" is doing something - until "B" stops overlaping it.

    2.Every time "B" is in "distance(Ax, Bx, Ay, By) < 100" "A" is doing something - until "B" is in "distance > 100".

    In first example you have two sprites - one sprite "A" and one sprite "detector" (which has to be always set to "A" position" for this to work)

    In second example there's only one sprite "A" and detection is made by events.

    If i'm thinking correctly second example should be faster, right?

  • Depends on what collision detection your using, and how many objects your using. A few would be pretty much negligible in either case.

  • Made "A" with bullet behavior with random angle at start. When "B" overlaps "A"s detector (simple - Is overlaping another object) "A" is speeding up a little and angle is se to "B" direction.

    I've already do some tests with 1st example - works fine with 50 "A" sprites - 60fps all the time. Big slowdown starts with more than 100 sprites (200 counting "A" and detector) from 60 to 12fps.

  • Well that's adding all those individual xy vectors to keep track of.

    If you make static objects with only a few object that move you should be able to get into the hundreds, if not thousands.

  • I'm aming opposite, few static objects and many moving :)

    gonna test 2nd example tomorow (well it's 4' o clock in the mornig so today) with my current setup and compare results.

  • I did test 2nd example and as I thought it is faster. I was able to create 400 sprites with full 60fps.

    about 450 sprites - 45 fps - starts droping

    about 650 sprites - 12 fps - like in 1st example but was able to get over 6 times more sprites.

  • So basically you're saying that its faster to do distance checking?

  • Yes, on exactly same project setup

    [quote=]Made "A" with bullet behavior with random angle at start. When "B" overlaps "A"s detector (simple - Is overlaping another object) "A" is speeding up a little and angle is se to "B" direction.

    I've managed to create much more sprites with distance expression than with another sprite as a detector, to check "If "B" is in certain position relative to "A". Keeping 60fps mostly all the time.

  • How are you picking with distance?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • + System: For each A

       + System: distance(B.X, B.Y, A.X, A.Y) Lower than 512

       -> A: Set speed : 200 towards B

    simple "Compare values"

  • That for each may actually be slowing you down.

    A sprite expression for distance would come in handy.

  • + System: For each A

       + System: distance(B.X, B.Y, A.X, A.Y) Lower than 512

       -> A: Set speed : 200 towards B

    simple "Compare values"

    You don't want to use for each here - it's far faster to check them all at once with A: pick by comparison: distance(B.X, B.Y, A.X, A.Y) Lower than 512

    Try it again with that.

  • I never though of that to check distance using "pick by comparision" but i must admit, that's the best one so far.

    I start with 10 "A"'s on screen, after destroing one "A" it will spawn 10 more..

    ...i got bored after having over 2500 "A"'s on screen :)

    keeps framerate at 60 - start's to be a bit jumpy (56-60fps) after having 1000 on screen and you spawn some more, but it's only for "spawn time", then it back to 60fps.

  • ...strange. can't edit my post

    Anyway, after i'm done with these tests i'm confused. When when is best to use "For each".

    I always thought that if you want to do/check someting within same group/type of sprites just do it like

    +For each Sprite

    • condition - action

    And now i just realize that it's not necessary, question when i should and when i shold not use For each?

  • Why is "for each" slower, both expressions will be checking all the sprites anyway?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)