4
\$\begingroup\$

I have a ball bouncing around the screen. I can pick it up and drag it onto a "bucket".

When my touches finish, I use the containsPoint function to check and see if I have dropped the ball onto the bucket.

This works fine, however, I actually want to check whether the ball is dropped onto the bucket node's physics body because my "bucket" is actually just an oval, and so I've applied a physics body which is the same shape as the oval, so that the white space around the oval isn't included in the physics simulation.

I can't seem to find a "containsPoint" function for physics bodies. Can anyone advise on how I'd check for this?

To summarise, I want to drop a node, onto a specific part of another node (or its physics body) and trigger an event.

Thanks in advance.

\$\endgroup\$
1
\$\begingroup\$

I had similar question and I did use this solution. Construct CGPathRef and then do check using CGPathContainsPoint in touchesBegan method.

\$\endgroup\$
0
\$\begingroup\$

The simplest means of determining if there is contact after your touches finish is to alter the category of the "ball" to a category that registers contacts with the "bucket".

That is to say, your ball would have a category that ignores the bucket until the ball is dragged and the touches end (touchesEnd method), at which point the category of the SKPhysicsBody of the ball will be changed to a category that no longer ignores the bucket. A simple didBeginContact method executes your desired behavior for the ball being dropped in the bucket.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.