average coordinates

For questions about using Classic.

Post » Sat Jul 18, 2009 3:06 am

Is it possible to get an average X,Y coordinate from a group of objects?

Say I've used the selection box to select those blue boxes, I'm not sure how I'd get the coordinates of that red thing.
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

Post » Sat Jul 18, 2009 3:26 am

+ For each object
+ Object is in selected area
-> add .x to global('avX')
-> add .y to global('avY')
-> add 1 to global('numSelected')

+ Always
-> Set redcrossthing.x to (avX / numSelected)
-> Set redcrossthing.y to (avY / numSelected)
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Jul 18, 2009 4:39 am

whoa, thats a great simple idea. thanks!
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

Post » Sat Jul 18, 2009 10:28 am

If I'm not mistaken
[code:24m40yrr]Cubic(sprite1.x,sprite2.x,sprite3.x,sprite4.x,0.5)[/code:24m40yrr]
[code:24m40yrr]Cubic(sprite1.y,sprite2.y,sprite3.y,sprite4.y,0.5)[/code:24m40yrr]
Should get the average, or half the distance between all.
Image Image
B
161
S
48
G
89
Posts: 7,345
Reputation: 66,245

Post » Sat Jul 18, 2009 10:19 pm

Cubic is not an average, it's an interpolator.
Deadeye's code would do the trick
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests