Scale one object proportionally to the other

0 favourites
  • 7 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • 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?

  • 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 !

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

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

    EventSheet :

    <img src="https://photos-4.dropbox.com/t/0/AAAasQUEh9UtlEppNn7cieTrMrGuKbKb4VZrXncgf6HNGg/12/113235847/jpeg/1024x768/3/1372258800/0/2/sinPin1.jpg/4wddSfo64HH7COhVQoAnHvB8qIqlZig8R_SCHr_qy1k" border="0" />

    Layout and Ship Sine behavior :

    <img src="https://photos-4.dropbox.com/t/0/AAA-p1jT7KQA4GjLAgBt0rdeB2vKd4jmzZlB8bHqNhz6JA/12/113235847/jpeg/1024x768/3/1372258800/0/2/sinPin2.jpg/P6rv8B9YO5GpeLqiJ3NQbUwGY7MzjNo4Fo8O8sTgkD0" border="0" />

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

    <img src="https://photos-3.dropbox.com/t/0/AADEa1PQMDsPmH_80_2x6hAsWuE-0Svdwp7y10F-cY9EVQ/12/113235847/jpeg/1024x768/3/1372258800/0/2/sinPin3.jpg/5axC6DqBeQ7QDP22et6EmZYFGYGjNPYohYcEQlH9mkQ" border="0" />

    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.

  • 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 : )

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)