Search Unity

Scale a sprite from the center, not the origin

Discussion in 'Scripting' started by kevdotbadger, Jan 6, 2012.

  1. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    Hello, I have a flat image representing a sprite and I've set the sprite origin to the bottomLeft. When I use scaleLocal() it scales the image from the origin. Can I set the scale from the center? I'm using scaleLocal() to mirror the image.
     
  2. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    The most important question here is what 2D framework are you using?
    I'm assuming your using a framework because you list a specific origin and scaleLocal() as a function, which doesn't exist in the Unity API.
     
  3. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Add scale * (pivot - center) to the position you want.
     
    SoftWillowProductions likes this.
  4. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    Sorry I'm using localScale(); (http://unity3d.com/support/documentation/ScriptReference/Transform-localScale.html).

    I'm using 2dToolKit, but i've set all the sprites origin to the lower left so that all the sprites animate correctly. I contact the guy who made 2dToolKit and asked him for advice and he pointed me in the direction of localScale(). What I'm trying to do is flip the images horizontally, so that the sprite can walk both left and right. The issue is that they're getting flipped by the origin, so they "jump" from left to right.