skip to Main Content

I have a physics body that needs the y scale to be 0.2. I have been using the rectangleOfSize property to define my physics body, but am not sure how to change the y scale of it. I had changed the y scale earlier in the code, and would like to know if there is an easier way to do this other than having to go into photoshop and create a new image. I will provide example code if anyone needs me to. Thanks!

2

Answers


  1. Yes, there is an easier way! I recommend looking into SKAction. SKAction contains the class methods:

    + (SKAction *)scaleBy:(CGFloat)scale duration:(NSTimeInterval)sec;
    + (SKAction *)scaleXBy:(CGFloat)xScale y:(CGFloat)yScale duration:(NSTimeInterval)sec;
    
    Login or Signup to reply.
  2. Unfortunately, scaling the physicsBody in Spritekit would cause collisions to be bugged, I would recommend that you create a new physicsBody and assign it to the node instead.

    As to change the yScale of the node, you can simply call this function

    node.yScale = yourValue
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search