sprite-kitskactionskshapenode

Scale a trapezoidal SKShapeNode by width while preserving 45-45-90 triangles on sides


I have an SKShapeNode which is supposed to be a paddle in a breakout-style game which I would like to scale in width by some factor.

It looks like this:

image

After I run

[SKAction scaleXBy:3.f / 2.f y:1.0 duration:1.0],

it looks like this (ignore the other grey brick in the corner, that's just another paddle):

image

The problem is that the triangles on the side are no longer 45-45-90.


Solution

  • What you're essentially asking for is to scale the center rectangle without scaling the triangles at either end. To do that easily, you could create a compound of four nodes — a parent node that contains separate nodes for the three shapes. When you want to embiggen your paddle, scale the rectangle and move the triangles.