Sprite is overlaping or distance expression?

For questions about using Classic.

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

Post » Fri Jul 08, 2011 3:08 pm

That for each may actually be slowing you down.
A sprite expression for distance would come in handy.
B
1
G
1
Posts: 7
Reputation: 439

Post » Fri Jul 08, 2011 5:26 pm

[QUOTE=shinkan] + 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"[/QUOTE]

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.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Fri Jul 08, 2011 5:46 pm

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

Post » Fri Jul 08, 2011 6:00 pm

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

Post » Sat Jul 09, 2011 5:07 am

Why is "for each" slower, both expressions will be checking all the sprites anyway?
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Sat Jul 09, 2011 5:43 am

Don't know if I'm right, but it's propably because 'for each' is loop, and it runs on different level of calculations, instead of usual events, which runs one time per tick
B
2
S
2
G
2
Posts: 158
Reputation: 1,366

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests