How do I prevent a sprite from scaling

0 favourites
  • 5 posts
From the Asset Store
A set of 10 pixel art animated magic effects with icons. 2 Fire, 2 Earth, 2 Wind, 2 Water, Portal, Explosion.
  • I have a background on a layer and a sprite on another.

    I'm zooming in and out on the background layer with the mouse wheel, but I'd like to prevent the sprite from scaling.

    I could set the scale rate of the layer the sprite is in into zero, but that does not maintain its position in relation to the zoomed layer.

    To put it easier, imagine a transformation/rotation gizmo in a 3D application. You can zoom and pan the view, but the gizmo always maintains its position and size.

  • Just change the gizmo scale when you change the layer scale. You will have to reset the position too. Grab the gizmo's x and Y, and shove them into a variable. After the scale, then you can set position back to the gizmos X and Y.

    Is the center not in the middle of the Gizmo?

  • Thanks jojoe

    I tried scaling the gizmo down when i scale the layer up (and vice versa), like this:

    Set Layer 1 scale to LayerScale(1)+0.002

    Set Gizmo scale to LayerScale(1)-0.002

    but unfortunately it doesn't work as expected. It keeps scaling up with the layer, just with a slower rate.

    With this method though the position is maintained, so I don't need to do anything.

    The other method is to set the scale rate of the layer to zero (which solves the scaling problem), but messes up its position. In this case I can do as you said: keep track of the gizmo's X and Y and position it. The problem is that the 2 layers (one scaled the other not) seem to have different coordinates after scaling. I'm guessing I have to use CanvasToLayer or LayerToCanvas but I can't really grasp what's happening

  • Why not put the gizmo on a layer that does not get scale, and then snap it to whatever object needs the gizmo after the scale? The gizmo would be unaffected by the scale, but might need to be re-positioned.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks again jojoe

    I tried exactly what you said but as soon as I scale the layer, the position of the gizmo (which is on a layer with scale rate=0) becomes "relative".

    I'm trying to re-position it on the object every tick, but it only moves exactly on the object's origin when the background layer scale goes back to 1.

    I don't know how to explain it better and thanks again for your valuable help!

    EDIT: Attached a capx to better demonstrate what I mean

    dl.dropboxusercontent.com/u/14855413/ex1.capx

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