Precise resizing, restoring default size

This forum is currently in read-only mode.
  • Hi, I'm sorta kinda new to Construct and I've been doodling quite a bit in it lately, but there's two things that've been bugging me for a while and I can't seem to find the solution either on the wiki or these forums.

    The first is, is there a way to precisely change an object's dimensions, using % points of their current state? i.e. an object is 100x100 pixels, resize it to 50% of its original -> it's now 50x50 pixels. So far I've been using the object's size in pixels and manually deriving what the final size aught to be for width and height separately, but it'd be nice to know if there's an easier way to do this.

    Secondly, is there some way to restore an object to its default size, i.e. the size of the actual frame in the animation editor? Once in a while my hand slips while I'm placing objects and I accidentally stretch one out of proportion. Generally I can just Undo it easily enough but if it somehow escapes my notice I don't know what to do besides re-make the entire object. I figured there's got to be an option for this but I can't seem to find it?

    Thanks for any help

  • A slightly hacky way would be to get the object's width/height first.

    So

    On (somevent)

    set sprite1 width = sprite1.width/2

    set sprite1 height = sprite1.height/2

    This should halve its size. If you want a specific percentage, try multiplying by decimal fractions.

    eg. 50% = 0.5, 10% = 0.1, 33% = 0.33

    set sprite1 width = sprite1.width*0.5

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • While Squish showed a quick solution, it is not suitable for all needs.

    Imagine you would want to set the sprite's dimension to 50% and a few seconds later to 75%. Let's say the original dimensions were 100x100. Then we would want the sprite to first shrink to 50x50 and later grow to 75x75.

    (height omitted)

    1) width = width * 0.5 (the sprite is now 50x50)

    2) width = width * 0.75 (the sprite is now 37.5x37.5)

    You could keep track of when to grow and when to shrink, and calculating that 75% is 1.5 * 50% and therefore replace 2) with width = width * 1.5, but it gets more and more complex as you change the sizes.

    An easier way is to use the expressions Get original width/Get original height. They always return the original initial values regardless of any changes to the size.

    1) width = OriginalWidth * 0.5 (sprite is now 50x50)

    2) width = OriginalWidth * 0.75 (sprite is now 75x75)

  • Gotcha, I guess that'll take care of that problem. Grats!

    As to my second question, I guess it's just a matter of setting the object size to the dimensions of its 1st frame of the default animation. Guess I should've figured that out sooner instead of panicking

    Thanks again for the help guys!

  • Hey, nice. I didn't notice that you can get original width/height.

    Cheers for that Tula.

    As an add on:

    If you have non-default sizes to start with, you can store those at layout start into private variables.

    Eg. On layout start

    Set "origWidth" = sprite.width

    Set "origHeight" = sprite.height

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