Sprite is overlaping or distance expression?

» 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
160
S
69
G
44
Posts: 2,611
Reputation: 36,844

» 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
S
1
G
1
Posts: 7
Reputation: 589

» 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
96
S
34
G
33
Posts: 3,007
Reputation: 27,921

» 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.
B
160
S
69
G
44
Posts: 2,611
Reputation: 36,844

» 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?
B
160
S
69
G
44
Posts: 2,611
Reputation: 36,844

» Sat Jul 09, 2011 5:07 am

Why is "for each" slower, both expressions will be checking all the sprites anyway?
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,857

» 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