I have a large rectangular SKPhysicsBody
created with SKPhysicsBody(edgeLoopFrom:...)
. Inside that physics body are a bunch of balls that bounce around. When a notification appears, I show a view from the bottom of the screen. I want to resize the SKPhysicsBody
so the balls bounce off this notification view while it's on screen.
What I do now is
func updateWalls() {
let wallInsets = UIEdgeInsetsMake(bottomWallInset, 0, 0, 0)
scene.physicsBody = SKPhysicsBody(edgeLoopFrom:UIEdgeInsetsInsetRect(bounds, wallInsets))
}
In other words I just replace the old physics body with a new one with the new dimensions. This works, except that if any balls are in the region between the old dimensions and the new dimensions they get trapped and bounce off the outside of the wall and fall out of the world.
Is there an elegant way to animate the transition between the old and new wall bounds, such that any balls that lie at the bottom are "swept" up into the new dimensions, and guaranteed to remain inside the wall? You can't scale an SKPhysicsBody
directly.
In this situation, instead of resizing the physics body, it is probably easier to create a node to represent the notification. That is, make an SKNode that does not render anything, attach a physics body to it the same size as the notification view, and just move the node along with the notification view. You can create an animation for the node movement at the same speed as the view is animated. This should give the effect you need with less possibility of confusing the physics simulation.