How do I adjust one side of a square object independently?

Get help using Construct 2

Post » Sun Aug 14, 2016 2:57 am

I have a small 50 x 50 box (Scaled down) and when it is tapped it's position should stay the same and it should adjust in size to fit the Viewport, or seemingly do so. When the player is done the box should adjust back to it's original size and position. I only know how to move boxes and adjust width equally on both sided as well as height. I am unaware of how to adjust each side of the square according to it's potion within the Viewport. I was going to use Lerp for this, but I just don't know what to use for the box's edge or points. I am aware of Viewport Top, Left, Right, Bottom.

The box is just a solid color.
B
68
S
37
G
13
Posts: 242
Reputation: 12,787

Post » Sun Aug 14, 2016 3:10 am

You can adjust width and height separately in your object actions. Instead of change "size" just look for "width" or "height" only to apply just one or the other. Is this what you mean?

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Sun Aug 14, 2016 3:15 am

No. I know of that, the box isn't gonna be in the middle of the screen. It would look correct when it expands out but when it contracts it won't look correct. There would be a lag on the side that is closest to the edge of the Layout.
B
68
S
37
G
13
Posts: 242
Reputation: 12,787

Post » Sun Aug 14, 2016 3:20 am

I will probably have to use width and height and adjust the box's position when it is scaling down. I wish there was an easier way though.
B
68
S
37
G
13
Posts: 242
Reputation: 12,787

Post » Sun Aug 14, 2016 9:21 am

You can just lerp the size and position. It won't matter if it's in the middle of the screen or not - but if you're filling the entire layout/viewport with it then it will end up in the middle anyway.

If you lerp the width and height to the size you want, and lerp the position from it's "normal position" to "viewport center" then it should do what you want? I guess it depends on how you want it to behave though.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Sun Aug 14, 2016 9:59 pm

That is what I have been trying to do. For some reason I am having trouble with it. Instead of going to it's expanded size it treats the third number as a % (as it should) but it only moves once. As in if I have it at 0.5(or 0.1) it instantly makes the object 50%(or 10%) of the size it is supposed to be and it stops expanding. I thought maybe Time Scale was effecting it because I have Time Scale set to 0 when this is happening. I disabled the trigger to set Time Scale to 0. When Time Scale is 1 it still does the same.

I am sure it is the way I structured the events. I am needing an example of a box sprite expanding in size when clicked and contracting back when clicked again, or the conditions that should be used. I wanted it to be a function so it skips unneeded events unless clicked. I thought that may be the reason so I tried otherwise and it acts the same. It needs to be unaffected by Delta Time.

Thank you.
B
68
S
37
G
13
Posts: 242
Reputation: 12,787

Post » Sun Aug 14, 2016 11:52 pm

I found my error...
On lerp I had:

lerp(50, 800, 0.3)

I changed it to:

lerp(Object.Width, 800, 0.3)


I think it was interfering with itself, I should have noticed that rather quickly... opps.
B
68
S
37
G
13
Posts: 242
Reputation: 12,787

Post » Mon Aug 15, 2016 4:01 pm

Not really.
You did't change that '0.3' each tick, and therefor you got one value in return.
The lerp should be lerp(50, 800, 0>1), where '0>1' is a value that counts from 0 to 1 in a time you choose.

The solution you found is kinda a 'fake' solution. It works, well kinda, that lerp will never reach 800.

It works because the distance between 'Object.Width' and '800' gets smaller.

If you cant wrap your mind arround 'lerp' then maybe you better use LiteTween.
behavior-litetween_t70700

Just a friendly suggestion.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Aug 16, 2016 9:28 am

I don't fully understand
"You did't change that '0.3' each tick, and therefor you got one value in return."

I tried litetween before I posted this post. 'Time Scale' seemed to be interfering with it. I couldn't find anything in the manual or post about 'Time Scale' or "Delta Time'. I got it to work correctly but there was a delay in the 'Time Scale' variable change and I can't have that. The change has to happen instantly.

I understand how lerp works mathematically. It is actually very simple. It takes two values and finds the difference using a 0>1 number as a percent. 0.5 will take 50% off of the remaining difference until it can't any more. 100, 50, 25, 12.5 , 6.25, 3.125....etc

lerp(50, 800, 0.3) is only returning one value no matter where I put it.
The only logical thought I came up with is it is running lerp correctly but since it isn't getting a reference to the object itself it is always returning the same value.

I had it under a variable = 1 condition with and without 'Every Tick'
I had it by itself with no Condition with and without an 'Every Tick'

I am using 'Set Size' where it sets width and height at the same time.
I even tried doing 'Set Width' and 'Set Height' individually and it is only returning one value.

It just isn't working, it always returns one value.

I understand lerp(Object.Width, 800, 0.3) never reaches it's target.
It is why I put in a condition to fix it.

I've spent way to much time trying to make it work.
What I did made it work and it looks correctly when adjusting it's size and position.
I had to do this with "Set Position" as well.

I will gladly fix what I have if I can find an example Capx or if someone can point out why lerp(50, 800, 0.3) isn't working.

I can't find an example of someone not placing the first lerp value of something related to the object. The first lerp value is always object.X or object.Y in all of the examples I have found. I also can't find an example of someone using lerp to change the size of an object. I can only assume it is similar to moving an object with lerp.
B
68
S
37
G
13
Posts: 242
Reputation: 12,787

Post » Tue Aug 16, 2016 11:57 am

'0>1' means that it needs some coding like this (very basecaly):

Global variable .. number ... = zero.

Every tick > add 0.1 to number (with max 1 and a reset for the next lerp)
lerp(50, 800, number)

Now number steps from 0 to 1 in 10 steps and the lerp will got from 50 to 800 in 10 steps.

It is as easy as that !

What you do now is the equvalent of lerp(number,800,0.3)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

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