Upscale layer position offset fix

Get help using Construct 2

Post » Mon Mar 26, 2012 1:33 am

Hello all,

I have a large group of multiple objects. This group of objects needs to be able to be upscaled/downscaled as a whole, at runtime. I decided the most efficient way to do this is to put the objects on a separate layer, and scale this layer up/down.
The scaling works well, but the cluster of objects now seems to have a positional offset. It does not stay in one place as expected, but moves around relative to the viewing window. The cluster of objects is directly in the centre of the layout, if that simplifies things. There is no parallax.
Any way to fix/change/compensate for this?

Thanks, sqiddster
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Mon Mar 26, 2012 2:18 am

Is the layout smaller than the screen size it's scaling to? If so, you need to set unbounded scrolling to yes for centered things to actually be centered :)
B
6
Posts: 22
Reputation: 751

Post » Mon Mar 26, 2012 11:08 am

@MonstaMunch, this is not the issue. The layout is quite large, and unbounded scrolling is on anyway.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Mon Mar 26, 2012 11:35 am



The black layer is the original layer, the blue one is the sized layer, using the same center.

Indeed there is an offset between the original and resized ones.

"Lazy" solution, place all "swarm" objects in a family and reduce the size of each object of the family by a certain percentage.

New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Mon Mar 26, 2012 7:45 pm

@kyatric, the image you posted is indeed my problem.
However, the lazy solution you suggested simply makes all the objects bigger... how would I increase the size of the whole by adjusting the position of all the objects accordingly?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Mar 28, 2012 2:26 am

Hmm... any mathies care to help? How do I correctly adjust the object's positions and size so that they adjust to create a larger shape?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Mar 28, 2012 2:33 am

I guess it's a bit the same trigonometry formulas that we used for the rotary competition.

You need a "reference" point as the original distance and angle towards another "member" of the group of object, and on resize you use the layer's size as a factor instead of the new angle.

I guess that's for theory, for the formula itself unfortunately, I don't know.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Wed Mar 28, 2012 8:49 am

Well Kyat you said it all,
For the reference point you can take the average point
[code]Global number scale = 1
System: On Start of Layout
-> Object: set scale to scale
on anything
Local number xSomme = 0
Local number ySomme = 0
Local number cx = 0 // X center of scale
Local number cy = 0 // Y center of scale
[Empty]
    -> System: set scale to 0.5
System:Foreach object
   -> System: add object.X to xSomme
   -> System: add object.Y to ySomme
[Empty]
   -> System: set cx to xSomme/object.count
   -> System: set cy to ySomme/object.count
System: Foreach object
   -> Object: set distance to distance(cx,cy,self.X,self.Y)
   -> Object: set a to angle(cx,cy,self.X,self.Y)
[Empty]
   -> Object: set distance to self.distance/self.scale
   -> Object: set width to self.width/self.scale
   -> Object: set height to self.height/self.scale
   -> Object: set scale to scale
   -> Object: set distance to self.distance*self.scale
   -> Object: set width to self.width*self.scale
   -> Object: set height to self.height*self.scale
   -> Object: set X to cx+cos(self.a)*self.distance
   -> Object: set Y to cy+sin(self.a)*self.distance[/code]
Should work but untested.

Explanation :
[code]System: On Start of Layout
-> Object: set scale to scale [/code]We make sure each object always "knows" at which scale they are. Else if you want to put the scale to 0.5 when the scale is already at 0.5 you might end up with a scale at 0.25...

[code]on anything
Local number xSomme = 0
Local number ySomme = 0
Local number cx = 0 // X center of scale
Local number cy = 0 // Y center of scale
[Empty]
    -> System: set scale to 0.5
System:Foreach object
   -> System: add object.X to xSomme
   -> System: add object.Y to ySomme
[Empty]
   -> System: set cx to xSomme/object.count
   -> System: set cy to ySomme/object.count[/code] "On anything" 'cause it depends on your implementation.

We declare some local variables

We set the scale to whatever you want (here 0.5)

The rest is pretty much an average calculation. To take the average between a bunch of number you add them and then divide by the number of value you added. I do the addition in the foreach and the division in the [Empty] condition (for those who doesn't know [empty] is the same as "Every Tick")

[code] System: Foreach object
   -> Object: set distance to distance(cx,cy,self.X,self.Y)
   -> Object: set a to angle(cx,cy,self.X,self.Y)[/code]We calcultate the distance from the average point and the angle and we store them in instance variables 'distance' and 'a' ('angle' couldn't be used as it's the angle of the object).

[code] [Empty]
   -> Object: set distance to self.distance/self.scale
   -> Object: set width to self.width/self.scale
   -> Object: set height to self.height/self.scale
   -> Object: set scale to scale
   -> Object: set distance to self.distance*self.scale
   -> Object: set width to self.width*self.scale
   -> Object: set height to self.height*self.scale
   -> Object: set X to cx+cos(self.a)*self.distance
   -> Object: set Y to cy+sin(self.a)*self.distance[/code]As we only operate on instance variable properties we don't need a foreach (it's kinda implicit).
[1st to 3rd action] we bring distance and size back to what it would be at scale 1. As we always store the current scale in the 'scale' instance variable.
[4th action] We apply the 'scale' global number to the 'scale' instance variable (oh yeah just to confuse you :D)
[5th to 8th action] Then we apply the scaling transformation on distance and size.
[9th and 10th action] We move objects toward or away from the average center depending on 'distance' and 'a' (obviously angle never need to be scaled)

That's al foksYann2012-03-28 08:55:08
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Mar 28, 2012 11:18 am

Wow, thanks Yann! I'll try to implement this soon. I assume this will work for a family eh?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Mar 28, 2012 3:27 pm

As long as it uses family variable instead of instance variables yes
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Next

Return to How do I....?

Who is online

Users browsing this forum: Aserak2012, Colorfish, Waltuo and 4 guests