{"id":6432,"date":"2014-04-18T05:22:06","date_gmt":"2014-04-18T05:22:06","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/how-to-make-a-dynamic-body-static-in-cocos2d-v3-0-with-chipmunk-collection-of-common-programming-errors\/"},"modified":"2014-04-18T05:22:06","modified_gmt":"2014-04-18T05:22:06","slug":"how-to-make-a-dynamic-body-static-in-cocos2d-v3-0-with-chipmunk-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/how-to-make-a-dynamic-body-static-in-cocos2d-v3-0-with-chipmunk-collection-of-common-programming-errors\/","title":{"rendered":"How to make a dynamic body static in Cocos2d v3.0 with Chipmunk-Collection of common programming errors"},"content":{"rendered":"<p>As the error message states, you need to implement a post-step callback. To do this on Cocos2d 3.0 and with Objective Chipmunk you first need to import a new header file to access advanced chipmunk properties:<\/p>\n<pre><code>#import \"CCPhysics+ObjectiveChipmunk.h\"\n<\/code><\/pre>\n<p>Then add the callback in your collision handler:<\/p>\n<pre><code>-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB\n{\n    [[_physicsNode space] addPostStepBlock:^{\n        _player.physicsBody.type = CCPhysicsBodyTypeStatic;\n    } key:_player];\n}\n<\/code><\/pre>\n<p><strong>Note that I assume you have access to your CCPhysicsNode in <code>_physicsNode<\/code>.<\/strong> The Chipmunk Space of <code>CCPhysicsNode<\/code>is locked while the a physics step is calculated. During a calculation of a step collisions are resolved and objects are moved around &#8211; changing the body type during this calculation could result in unexpected behaviour.<\/p>\n<p>Therefore you add the <code>postStepBlock<\/code>callback. This is a place where a body type can be safely changed.<\/p>\n<p>The <code>key<\/code> value you pass into the callback is used to ensure that the code is only called once (especially useful when removing objects, but it also makes sense in this case).<\/p>\n<p>If also added an example implementation: https:\/\/www.makegameswith.us\/gamernews\/367\/make-a-dynamic-body-static-in-cocos2d-30-with-chi<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As the error message states, you need to implement a post-step callback. To do this on Cocos2d 3.0 and with Objective Chipmunk you first need to import a new header file to access advanced chipmunk properties: #import &#8220;CCPhysics+ObjectiveChipmunk.h&#8221; Then add the callback in your collision handler: -(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB { [[_physicsNode space] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6432","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6432"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6432\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}