1
votes

I'm currently developing a IOS game using SpriteKit.

I have a background which is SKShapeNode. Basically the path of this shape is a bezierPath with some curves. This path can be updated by the player using the touchBegan or touchMove trigger.

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event{
     CGPoint touchPoint = [[touches anyObject] locationInView:self.view];

     // Create path
     UIBezierPath* newPath = ...

     // Update path
     [self.backgroundShape setPath:newPath.CGPath];
     [self.backgroundShape setPhysicsBody:[SKPhysicsBody bodyWithEdgeLoopFromPath:newPath.CGPath]];
} 

While updating the path of the background, some other SKNodes can enter inside my background.

Let's say we have the floor of a table at y0 (original vertical position) with some boxes on it (SKNodes). When updating the physics of the table to another vertical position (for instance y0 + deltaY), the boxes (which are affected by gravity) fall down at the bottom of the screen.

How can I prevent this ? I want to update the physics of the table but I want the boxes to stay on it.

Short video of the current issue

Thanks,

1
What behavior actually ? Please describe a problem better, eg. add some pictures, animation ... Sorry but the question is unclear and from the provided code it can't be said what is the problem. My best guess is that you have a problem with collision bit masks setup...Whirlwind
I have edited my post. Not sure I'm very clear .. @WhirlwindJohn smith
Okay now it is a bit clearer. Updating physics body is always a thing. Did you set the masks correctly when you are re-creating boundary?Whirlwind
I'm using the code post in my touchMoved method. Nothing more. SO maybe I have forget something somewhere .. Basically I update the path of the shape and then its physics body. @WhirlwindJohn smith
it would be VERY helpful if you could post a short video of this issue, or a drawing of some sort. Quicktime will let you take a screen recording of your simulator.Fluidity

1 Answers

0
votes

In your gamescene:

func keepBallOnTable() {
  if ball.frame.minY < table.frame.maxY {
    ball.position.y = table.frame.maxY + (ball.size.height / 2) + 1
  }
}

override func didFinishUpdate() {
  keepBallOnTable()
}

You will have to translate to objC :P

Video results of implementation

gist of the whole gamescene

Physicsbody and things like .moveTo and .position don't mix very well. You will have to fight the physics system everytime you try to mix them. Hence, the function I created above :)