Chipmunk Collision callback solution for short-time re-entry

Source: Internet
Author: User

The collision behavior in the Chipmunk engine may be slightly different from the general perception in detail.

For example, the collision callback method may be re-entered. Do not know the method (function) to re-enter the concept of children's shoes can be self-gu brother or degree Niang.

The first collision method has not yet returned, and the second collision callback is called again. As to whether they are running on the same thread, this does not know. At least I'm in the middle of a thread in my debugging. However, the thread in a line will also occur. Here the study is not deep, there are errors please point out.

The first collision callback method is as follows:

-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair star:(CCNode *)star                         stick:(CCNode *)stick{    StarType starType;    if (!star) {         returnYES;    }     starType = ((Star*)star).starType;     nil;    }    //working    [star removeFromParentAndCleanup:YES];    returnYES;}

The working in the code above occasionally executes 2 times in a short period of time. 1th modification It is not possible to move the star Removefromparentandcleanup call to the front of the method.

The 2nd Amendment is as follows:

@synchronized(self){        if (!star) {            returnYES;        }        starType = ((Star*)star).starType;        [star removeFromParentAndCleanup:YES];        nil;    }    //working...

Still, it is possible that the value of star after calling the Remove method will not be nil, causing the if judgment to fail.

The 3rd modification adds the If judgment condition as:

if (!star || !star.parent) {      return YES;}

Code logic works fine, in the second re-star.parent must be (still not sure, said "should be" more appropriate;) nil, so avoid the call working logic again.

Maybe I have a problem with my code logic, and I can't depend on the number of times the method was re-entered. Because of the uncertainty of the physics engine callback, it is obvious that the problem occurred.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Chipmunk Collision callback solution for short-time re-entry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.