Search code examples
cocos2d-iphone

Calculate scale portion in cocos2d


enter image description here

As you see on the image above, I have 2 rectangles. The yellow rect is scaled from the red one.

I know width, height and crossline(c) of the red and the yellow we only know the crossline so : How can I know the scale portion, width height of the yellow rect.

By the way, I use this to make a program that I have eight point for touch & drag to transform the sprite. anyone have example code or sth let me know


Solution

  • First, determine the scale ratio: Scale ratio = Crossline of Yellow / Crossline of Red.

    then use it to find sides:

    Width of yellow = width of red * scale ratio

    Height of yellow = height of red * scale ratio