[SOLVED] How do I make an object scale based on Y?

0 favourites
  • 8 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi everyone,

    I'm trying to make a sprite scale up in size as it goes up in Y value on the layout (like trying to simulate just a little bit of perspective for an adventure game). I know the answer must be simple, but my mind must be even simpler because I have a really hard time trying to figure this out. Any help would be really appreciated. Thanks!

  • Try this:

    Create instance variables : PlayerWidth & PlayerHeight and set them to original size

    Then in event's

    -Is Player moving, every tick :

    ---set player size: Width to: varPlayerWidth + (Y/n), Height to: varPlayerHeight + (Y/n),

    where "n" is a number you will divide Y with so you won't get extremely huge character.

    You could try using scaling too, which will probably work better, but can't remember how to do it from top of my head.

  • Try "Set Scale to (1/480)*sprite.Y"

    480 being the set screen height.

    Or "Set Scale to 0.5+(1/480)*sprite.Y"

    so that mid screen is scale 1, original size.

  • Try "Set Scale to (1/480)*sprite.Y"

    480 being the set screen height.

    Or "Set Scale to 0.5+(1/480)*sprite.Y"

    so that mid screen is scale 1, original size.

    Wouldn't be better to use system's ScreenHeight instead of 480?

  • I simplified it as much as possible so that it was easier to understand and complicate back up to the actual situation.

    1/480 is quicker to comprehend you are dividing the screen into a fractional size that you use as the steps in size. Avoiding all the complications like parallax, window height, and fluctuating numbers that cause flickering when sitting still.

    (also why I left 0.5 out of the 1st example.)

    (ScreenHeight is actually a Browser expression: Retrieve the dimensions of the entire device screen. This is the complete display area available to the operating system.)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks guys, both of you were a big help! Paradox, your solution is the one that seems to work best, but I appreciate seeing multiple ways of getting the job done, and it all helps me understand expressions a little more.

    Update, I got things working just how I wanted! I didn't need the scaling to go all the way from 1 to zero, so I made some adjustments to make sure the scaling wouldn't be so drastic from bottom to top of the layer.

    Here's what I got going

    My layout is 720 pixels tall. I also wanted movement speed to scale down with the PlayerAnimation size too, so the illusion wouldn't be broken

    System: Every Tick

    -Set scale to (1/2160)*(PlayerAnimations.Y + 1440)

    -Set 8Direction Maximum Speed to (300/2160)*(PlayerAnimations.Y+1440)

    I found out that if I increased the denominator to 3 times the size of my layout, and added the remainder back to the PlayerAnimations.Y, I could keep the Y(720) yielding a 1 scale, while having the Y(0) yield me a .6667 scale.

    Once again, thanks for all the help guys!

  • Great to hear! I should have thought about the speed scaling, I bet that looks good.

    It's always gets a lot more complicated once you squeeze it in what you are doing.

  • [quote:8m9yrmod]Here's what I got going

    My layout is 720 pixels tall. I also wanted movement speed to scale down with the PlayerAnimation size too, so the illusion wouldn't be broken

    System: Every Tick

    -Set scale to (1/2160)*(PlayerAnimations.Y + 1440)

    -Set 8Direction Maximum Speed to (300/2160)*(PlayerAnimations.Y+1440)

    I found out that if I increased the denominator to 3 times the size of my layout, and added the remainder back to the PlayerAnimations.Y, I could keep the Y(720) yielding a 1 scale, while having the Y(0) yield me a .6667 scale.

    Thanks for posting. This is exactly what I am looking for. It gives me a 100% sized sprite at the bottom of the screen and not too tiny at the top.

    The trouble is that I don't quite understand how you worked it out and I would really like to.

    If you or anyone else could explain this in an artist friendly way I would very much appreciate it.

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