Scale one object proportionally to the other

Get help using Construct 2

Post » Wed Jun 26, 2013 11:46 am

Hi,

I'm trying to scale one object proportionally to the other. Currently I have a flying ship, which has an energy bar on it. The bar is a separate object since it changes its height constantly but it is pinned to the ship so when the ship moves it goes along with it.
I've put some SINE behaviors on the ship so it looks more like it's flying. the horizontal and vertical sine are not a problem, but the SIZE one is. I cannot get the bar to scale the same way so it remains proportional to the ship.

I cannot access the ship's scale and as Ashley says in here, not all objects have the same scale which is pretty logical. I've tried accessing the SINE parameters of the ship and putting them on the bar's SINE behaviour but that didn't work out either since the same numbers (magnitude, period) apply differently on the object depending on its size. I'd try to make them the same manually but the problem is that the ship's sine has randoms in it.

So can anyone tell me how to achieve this effect? So that the ship and the bar on the ship scale in a way that will be proportional?   bigproblem012013-06-26 11:46:59
B
6
S
1
Posts: 32
Reputation: 789

Post » Wed Jun 26, 2013 1:25 pm

Ok, so this was harder than I thought ^^
I managed to get it work though : capx
I had to create 2 variables though, baseWidth for the ship and the bar. It should be possible to get the current scale of the ship from the behavior, but I only get the curent value (going from -magnitude to +magnitude) and I have no idea how it is then used in the sin behavior to change the size of the ship... With a magnitude of 50, I thought my sprite was going from +50% to -50% size, but it didn't seem to be consistant with the rest...
Well, by storing the initial values of the ship, it is possible to deduce the current scale, and apply it to your bar. You will have to add the shipScale (=curentWidth/baseWidth) in the function that sets the bar height though. In my exemple, I used a sine behavior on the bar too, set to "value only", and handled the changing size in the events.
Fell free to ask if something is not clear !
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Wed Jun 26, 2013 2:29 pm

Hi, thanks so much for the effort, is there a way you could save this in 132 version? the thing is i'm working on a game right now and am afraid to change versions because my teammate told me he installed 136 and got some permanent visual bug which he cannot fix no matter how he removes and reinstalls construct
B
6
S
1
Posts: 32
Reputation: 789

Post » Wed Jun 26, 2013 2:53 pm

I can't, sorry. But here are the screenshots :
EventSheet :

Layout and Ship Sine behavior :

Bar Sine Behavior (to simulate how you constantly change the bar height)

Initialy, I put the bar and the ship on the same coordonates, I separated them to be clearer here.
The ship is 100px orange, and 50px blue, just to check the bar height : the bar being 50px height with a magnitude of +/-50px, it should go from 0px height to covering exactly all the orange if the scalling is right.
The width of the 2 objects were the same for me, just to check the scalling too, but you can change base width with no problems.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Wed Jun 26, 2013 5:39 pm

Thanks Guizmus for all the trouble you went through. I opened your file nonetheless by installing the new construct and keeping the old one :D (and it DID bug, what it does is it changes your event sheet colors and you have to reset them to default, I don't know why it does that)

Your solution works on its own, it just turns out that in my game it'll be way harder to implement, since the bar height changes depending on whether some sprites overlap or not (it increases if they do and decreases if they don't). Also, the image points of the bar and the ship are not on the same spot since the ship needs to decrease in size from all around (thus it has its image point in the middle) while energy bar needs to decrease in height from only one side, (thus it needs to have an image point on the edge).

Anyway, thanks for the help, I'll keep it in mind for future projects, and sorry for making you go extra mile to upload the screenshots and all : )
B
6
S
1
Posts: 32
Reputation: 789

Post » Wed Jun 26, 2013 5:55 pm

Hum... screens link are dead... My bad.
The only important thing in my solution, and that could be implemented on whatever project (maybe ^^) is the maths themselves. If you accept to store both baseWidth (ship and bar), you can update the bar easily.
In particular, for the height, if you replace all the "set height to" by a call to a function that would set the height you want after multiplying it by ship.width/ship.baseWidth (basicaly the current scale of the ship), you should have the exact scale you want for the bar.
The only problem I ran into that seems hard to go by (not impossible, hard) is the origin point. I had to put it top left for both objects. If you don't do so, you will have to calculate the relative movement of the origin, as the Pin behavior don't seem to apply to it.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Wed Jun 26, 2013 9:18 pm

ah no worries, I've managed to see the screens before they went south, but still preferred to download the capx and look into it.
Yes, your solution works good and when I was trying it out I did as you just said - set the height to whatever I wanted and then multiplied it by the ship width ratio and it worked. The problem that remained was also as you just said - the origin point.
I need the bar to decrese from one end only so it has to have an origin on the edge. In ship's case it has to be in the middle to create and illusion as if the ship is levitating up and down (from topdown view)..
In the end I realized that I don't really need that feature since the ship kinda flies on top of rails, grazing them and its illogical for it to go through the rails.. but then again, I still posted the problem since whenever I encounter something I can't deal with alone, I bring it here to eventually find the answer and get better at the engine.
B
6
S
1
Posts: 32
Reputation: 789


Return to How do I....?

Who is online

Users browsing this forum: Eren, t redeemed t and 1 guest