How do I get the scale of a sprite?

  • You can set the scale of an individual sprite, but I want to make a sprite shrink over time by referencing the sprites current scale. However, I do not see any scale expressions listed.

    For example: On Timer"Shrink", set scale to sprite.scale-0.2

    Is this possible, or do I need to maintain a separate variable to track the sprite's current scale?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why not use size - as in width and height?

  • Yeah, there is no scale expression, as you can't get scale in reverse if the width is different than the height.

    A variable is the only way to go, but it also renders the scale action pointless.

  • Somebody Because it's fussing with two expressions instead of one, and there's extra math involved if you want to change size via percentage change, and you have to store two variables to hold the original size data as well. It's just plain clunky. Thank you though. The built in scale system is quite nice, it is simply lacking when you want to read the current scale setting is all. (IMHO)

    newt I don't quite understand your "scale in reverse" comment, please elaborate a little?

    Also:>"A variable is the only way to go, but it also renders the scale action pointless."

    Do you mean the action is pointless because we have a redundant variable? Because you still have to use the set scale action to make the sprite's scale actually change. It's just a hassle to not be able to read an objects current scale, thus the need for a somewhat redundant variable to track the current scale.

  • You make a variable called myscale, multiply the width and the height by that number.

    You would then know what the scale is.

    The system scale is what is now redundant.

  • newt Oh, I see where you were going. I was thinking of using a variable that simply gets changed anytime the scale gets changed so that there would be some way of reading the current scale. Thanks for explaining that.

  • newt Ok, I just discovered something new: A scale of 1 makes the sprite the size of the *original image*. So if in the editor you shrank a 64x64 sprite down to 32x32 and then at runtime set scale to 1, that sprite would pop back to 64x64. I thought it would go back to the size set in the editor. Live and learn. I think I will do what you suggest, since many of my sprites are not the same size as the original image. Thanks again.

  • You can Access to the sprite scale, setting your varible like that

    myScale = Sprite.height / Sprite.imageHeight

    I hope I've helped

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