# Sprite is overlaping or distance expression?

For questions about using Classic.

### » Fri Jul 08, 2011 2:40 am

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?
shinkan2011-07-08 02:41:29
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

### » Fri Jul 08, 2011 2:44 am

Depends on what collision detection your using, and how many objects your using. A few would be pretty much negligible in either case.
B
1
G
1
Posts: 7
Reputation: 439

### » Fri Jul 08, 2011 2:51 am

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.
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

### » Fri Jul 08, 2011 3:02 am

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.
B
1
G
1
Posts: 7
Reputation: 439

### » Fri Jul 08, 2011 3:12 am

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.
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

### » Fri Jul 08, 2011 11:16 am

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.
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

### » Fri Jul 08, 2011 12:01 pm

So basically you're saying that its faster to do distance checking?
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

### » Fri Jul 08, 2011 12:22 pm

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.[/quote]

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.
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

### » Fri Jul 08, 2011 2:12 pm

How are you picking with distance?
B
1
G
1
Posts: 7
Reputation: 439

### » Fri Jul 08, 2011 2:22 pm

+ 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"
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Next

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: Google [Bot] and 2 guests