{"id":834,"date":"2015-08-04T00:00:27","date_gmt":"2015-08-03T15:00:27","guid":{"rendered":"http:\/\/androiphone.uvs.jp\/?p=834"},"modified":"2017-03-23T10:52:55","modified_gmt":"2017-03-23T01:52:55","slug":"andengine-box2d-%e7%b0%a1%e5%8d%98%e3%81%aabody%e3%80%81%e8%a4%87%e9%9b%91%e3%81%aa%e5%bd%a2%e6%85%8b%e3%81%aebody%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8b%e3%80%80%e3%81%9d%e3%81%ae2","status":"publish","type":"post","link":"https:\/\/androiphone.uvs.jp\/?p=834","title":{"rendered":"[AndEngine Box2d] \u7c21\u5358\u306aBody\u3001\u8907\u96d1\u306a\u5f62\u614b\u306eBody\u3092\u3064\u304f\u308b\u3000\u305d\u306e2"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\"><strong>(2)\u8907\u6570\u306eVector2[]\u914d\u5217\u304b\u3089Body.\u3092\u4f5c\u308aSprite\u3068\u95a2\u9023\u4ed8\u3051\u308b(\u8907\u96d1\u306a\u5f62\u614b\u306eBody)<\/strong><\/span><\/p>\n<p>\u307e\u305a\u3001\u3069\u3046\u3084\u3063\u3066\u8907\u6570\u306eVector2[]\u3092Body\u306b\u6e21\u3059\u306e\u304b\u304c\u3001\u610f\u5916\u306b\u60c5\u5831\u304c\u306a\u3044\u3002\u521d\u3081\u306fBody\u3092joint\u3067\u3064\u306a\u3054\u3046\u3068\u601d\u3063\u305f\u304c\u3001\u3069\u3046\u3082\u3061\u304c\u3046\u3089\u3057\u3044\u3002\u540c\u3058\u60a9\u307f\u3092\u3082\u3064\u30b5\u30a4\u30c8\u306b\u3044\u304d\u3064\u3044\u305f\u3002<\/p>\n<p><a href=\"http:\/\/morishin127.tumblr.com\/post\/46425988233\/ioscocos2d-box2d%E8%A4%87%E6%95%B0%E3%81%AE%E5%9B%B3%E5%BD%A2%E3%82%92%E7%B5%84%E3%81%BF%E5%90%88%E3%82%8F%E3%81%9B%E3%82%8B\">http:\/\/morishin127.tumblr.com\/post\/46425988233\/ioscocos2d-box2d%E8%A4%87%E6%95%B0%E3%81%AE%E5%9B%B3%E5%BD%A2%E3%82%92%E7%B5%84%E3%81%BF%E5%90%88%E3%82%8F%E3%81%9B%E3%82%8B<\/a><\/p>\n<p>iOS\u3068Cocos2d-x\u3060\u304cBox2d\u3067\u3042\u308b\u305f\u3081\u3001\u6982\u5ff5\u7684\u306b\u306f\u4e00\u7dd2\u3067\u3042\u308d\u3046\u3002\u3053\u306e\u30b5\u30a4\u30c8\u306e\u30b3\u30fc\u30c9\u306b\u3088\u308b\u3068Body.CreateFixture\u3067shape\u3092\u8907\u6570\u8ffd\u52a0\u3057\u3066\u3044\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3089\u3057\u3044\u3002 \u3053\u3053\u3067\u3001shape\u3068\u306f?\u306a\u3069\u8272\u3005\u7591\u554f\u304c\u3042\u3063\u305f\u304c\u3001PhysicsFactory.createPolygonBody\u306e\u30bd\u30fc\u30b9(\u4e0b\u30b3\u30fc\u30c9)\u3092\u898b\u3066\u307f\u308b\u3068\u306a\u3093\u3068\u306a\u304f\u7406\u89e3\u3067\u304d\u305f\u3002<\/p>\n<p>[java]<br \/>\n\tpublic static Body createPolygonBody(final PhysicsWorld pPhysicsWorld, final IShape pShape, final Vector2[] pVertices, final BodyType pBodyType, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) {<br \/>\n\t\tfinal BodyDef boxBodyDef = new BodyDef();<br \/>\n\t\tboxBodyDef.type = pBodyType;<\/p>\n<p>\t\tfinal float[] sceneCenterCoordinates = pShape.getSceneCenterCoordinates();<br \/>\n\t\tboxBodyDef.position.x = sceneCenterCoordinates[Constants.VERTEX_INDEX_X] \/ pPixelToMeterRatio;<br \/>\n\t\tboxBodyDef.position.y = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y] \/ pPixelToMeterRatio;<\/p>\n<p>\t\tfinal Body boxBody = pPhysicsWorld.createBody(boxBodyDef);<\/p>\n<p>\t\tfinal PolygonShape boxPoly = new PolygonShape();<\/p>\n<p>\t\tboxPoly.set(pVertices);<br \/>\n\t\tpFixtureDef.shape = boxPoly;<\/p>\n<p>\t\tboxBody.createFixture(pFixtureDef);<\/p>\n<p>\t\tboxPoly.dispose();<\/p>\n<p>\t\treturn boxBody;<br \/>\n\t}<br \/>\n[\/java]<\/p>\n<p>2-3\u884c\u76ee\u306fBody\u81ea\u4f53\u306e\u8a2d\u5b9a(BodyDef\u5b9a\u7fa9)\u3001\u5f15\u6570\u3088\u308a\u884c\u3046\u3002staticBody(\u91cd\u529b\u306e\u5f71\u97ff\u3092\u53d7\u3051\u306a\u3044)\u3001DynamicBody(\u91cd\u529b\u306e\u5f71\u97ff\u3092\u53d7\u3051\u308b)\u306a\u3069\u5f8c\u307b\u3069\u30b3\u30fc\u30c9\u3092\u8f09\u305b\u308b\u3002<\/p>\n<p>5-7\u884c\u76ee\u306f\u5ea7\u6a19\u7cfb\u306e\u5909\u63db\u3002Body\u3068\u5b9f\u5ea7\u6a19\u306f\u9055\u3046\u3068\u306e\u3053\u3068\u3002\u304a\u307e\u3058\u306a\u3044\u3068\u601d\u3063\u3066\u304a\u3044\u3066\u3088\u3044\u3068\u306e\u3053\u3068\u3002<\/p>\n<p>9\u884c\u76ee\u3067BodyDef\u304b\u3089Body\u3092\u751f\u6210\u3059\u308b<\/p>\n<p>11\u884c\u76ee\u3067Shpae\u30af\u30e9\u30b9\u306e\u30b5\u30d6\u30af\u30e9\u30b9\u306ePolygonShape\u3092\u751f\u6210\u3002<\/p>\n<p>13\u884c\u76ee\u3067PolygonShape\u306eshape\u306bpVertices\u306eVector2[]\u914d\u5217\u3092\u6e21\u3059<\/p>\n<p>14\u884c\u76ee\u3067\u5f15\u6570\u3067\u6e21\u3055\u308c\u305fFIXTURE_DEF(<a href=\"http:\/\/androiphone.uvs.jp\/?p=823\">\u305d\u306e1<\/a>\u53c2\u7167)\u306eshape\u306bPolygonShape\u3092\u6e21\u3059<\/p>\n<p>16\u884c\u76ee\u3067Body\u306bpFixtureDef(FIXTURE_DEF)\u3092\u767b\u9332\u3059\u308b<\/p>\n<p>18\u884c\u76ee\u3067PolygonShape\u306e\u89e3\u653e \u3068\u3044\u3046\u624b\u7d9a\u304d\u304c\u884c\u308f\u308c\u3066\u3044\u308b\u3002<\/p>\n<p>\u5148\u306e\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3088\u308a11\u884c\uff5e18\u884c\u3092Vector2[]\u914d\u5217\u6570\u3060\u3051\u30eb\u30fc\u30d7\u3055\u305b\u308c\u3070\u3088\u3044\u3053\u3068\u304c\u5206\u304b\u3063\u305f\u3002 \u6e96\u5099\u3068\u3057\u3066\u3001\u305d\u306e1\u3067\u3001\u4f5c\u6210\u3057\u305f10\u500b\u306eVector2[]\u914d\u5217\u3092\u5b9a\u7fa9\u90e8\u3092\u8a18\u8f09\u3057\u3066\u304a\u304f\u3002\u3061\u3087\u3063\u3068\u30b9\u30de\u30fc\u30c8\u306a\u65b9\u6cd5\u304c\u601d\u3044\u304b\u306a\u304b\u3063\u305f\u304c\u3001ArrayList\u306b10\u500b\u306eVector2[]\u3092\u7a81\u3063\u8fbc\u3093\u3060\u3002 \u30eb\u30fc\u30d7\u3067\u56de\u305d\u3046\u3068\u601d\u3063\u305f\u304cAndEngine Vertex Helper\u3067\u76f4\u63a5\u5b9a\u7fa9\u6587\u304c\u51fa\u6765\u308b\u306e\u3067\u3001\u305d\u3093\u306a\u3081\u3093\u3069\u304f\u3055\u304f\u306f\u306a\u3044\u304c\u3001\u3084\u305f\u3089\u3068\u9577\u304f\u306a\u308b\u3002<\/p>\n<p>[java]<br \/>\n       ArrayList&amp;amp;amp;lt;Vector2[]&amp;amp;amp;gt; vertices_list = new  ArrayList&amp;amp;amp;lt;Vector2[]&amp;amp;amp;gt;();<\/p>\n<p>        final Vector2[] vertices1 = {<br \/>\n        \t\tnew Vector2(-0.46000f*width, -0.11579f*height),<br \/>\n        \t\tnew Vector2(-0.19000f*width, -0.23684f*height),<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices1);<\/p>\n<p>        final Vector2[] vertices2 = {<br \/>\n        \t\tnew Vector2(-0.19000f*width, -0.23684f*height),<br \/>\n        \t\tnew Vector2(-0.00500f*width, -0.46316f*height),<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices2);<\/p>\n<p>        final Vector2[] vertices3 = {<br \/>\n        \t\tnew Vector2(-0.00500f*width, -0.46316f*height),<br \/>\n        \t\tnew Vector2(+0.19000f*width, -0.26842f*height),<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices3);<\/p>\n<p>        final Vector2[] vertices4 = {<br \/>\n        \t\tnew Vector2(+0.19000f*width, -0.26842f*height),<br \/>\n        \t\tnew Vector2(+0.45500f*width, -0.11579f*height),<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices4);<\/p>\n<p>        final Vector2[] vertices5 = {<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<br \/>\n        \t\tnew Vector2(+0.45500f*width, -0.11579f*height),<br \/>\n        \t\tnew Vector2(+0.32000f*width, +0.14737f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices5);<\/p>\n<p>        final Vector2[] vertices6 = {<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<br \/>\n        \t\tnew Vector2(+0.32000f*width, +0.14737f*height),<br \/>\n        \t\tnew Vector2(+0.30000f*width, +0.47368f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices6);<\/p>\n<p>        final Vector2[] vertices7 = {<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<br \/>\n        \t\tnew Vector2(+0.30000f*width, +0.47368f*height),<br \/>\n        \t\tnew Vector2(-0.00500f*width, +0.41053f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices7);<\/p>\n<p>        final Vector2[] vertices8 = {<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<br \/>\n        \t\tnew Vector2(-0.00500f*width, +0.41053f*height),<br \/>\n        \t\tnew Vector2(-0.28500f*width, +0.45789f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices8);<\/p>\n<p>        final Vector2[] vertices9 = {<br \/>\n        \t\tnew Vector2(-0.31500f*width, +0.14211f*height),<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<br \/>\n        \t\tnew Vector2(-0.28500f*width, +0.45789f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices9);<\/p>\n<p>        final Vector2[] vertices10 = {<br \/>\n        \t\tnew Vector2(-0.46000f*width, -0.11579f*height),<br \/>\n        \t\tnew Vector2(+0.00000f*width, -0.00000f*height),<br \/>\n        \t\tnew Vector2(-0.31500f*width, +0.14211f*height),<\/p>\n<p>        };<br \/>\n        vertices_list.add(vertices10);<br \/>\n[\/java]<\/p>\n<p>\u3053\u3053\u304b\u3089\u3001\u8907\u6570\u306eVector2[]\u914d\u5217\u3092shape\u306b\u3057\u3066Body\u306b\u767b\u9332\u3057\u3066\u3044\u304f\u90e8\u3067\u3042\u308b\u3002<\/p>\n<p>[java]<br \/>\n        BodyDef bDef = new BodyDef();<br \/>\n        bDef.type = BodyType.DynamicBody;<br \/>\n        bDef.fixedRotation = false;  \/\/\u56de\u8ee2\u8a31\u53ef<br \/>\n        bDef.position.x = sp.getX() \/ PIXEL_TO_METER_RATIO_DEFAULT;<br \/>\n        bDef.position.y = sp.getY()  \/ PIXEL_TO_METER_RATIO_DEFAULT;<\/p>\n<p>        Body body = this.mPhysicsWorld.createBody(bDef);<\/p>\n<p>        for(Vector2[]  v : vertices_list){<br \/>\n            PolygonShape shape = new PolygonShape();<br \/>\n            shape.set(v);<br \/>\n            FIXTURE_DEF.shape = shape;<br \/>\n            body.createFixture(FIXTURE_DEF);<br \/>\n            shape.dispose();<br \/>\n        }<\/p>\n<p>        attachChild(sp);<br \/>\n\t\tthis.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(sp, body, true, true));<br \/>\n[\/java]<\/p>\n<p>BodyDef\u3067Body(Sprite)\u306e\u56de\u8ee2\u8a31\u53ef\u3084\u3001\u9759\u6b62\u7269\u4f53\u306a\u306e\u304b\u3001\u52d5\u7684\u7269\u4f53\u306a\u306e\u304b\u3092\u5b9a\u7fa9\u3059\u308b\u3002 <a href=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2015\/08\/ae46b1f460ee46f789c27b264a6cb421.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-837\" src=\"http:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2015\/08\/ae46b1f460ee46f789c27b264a6cb421-300x287.png\" alt=\"\u540d\u79f0\u672a\u8a2d\u5b9a-1\" width=\"300\" height=\"287\" srcset=\"https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2015\/08\/ae46b1f460ee46f789c27b264a6cb421-300x287.png 300w, https:\/\/androiphone.uvs.jp\/wp-content\/uploads\/2015\/08\/ae46b1f460ee46f789c27b264a6cb421.png 500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u4ee5\u4e0a\u3067\u3001\u8907\u6570\u306eVector2[]\u914d\u5217\u3092Body\u306b\u767b\u9332\u3057\u7269\u7406\u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u304c\u3067\u304d\u308b\u72b6\u614b\u3068\u306a\u308b\u306f\u305a\u3067\u3059\u3002 \u88dc\u8db3<\/p>\n<p>[java]<br \/>\n\t\/\/\u8907\u6570\u306eVertices[]\u914d\u5217\u306e\u30ea\u30b9\u30c8\u304b\u3089Body\u3092\u751f\u6210<br \/>\n\tpublic static Body createVerticesListBody(final PhysicsWorld pPhysicsWorld, final IShape pShape, final  ArrayList&amp;amp;amp;lt;Vector2[]&amp;amp;amp;gt; vertices_list , final BodyType pBodyType, final FixtureDef pFixtureDef) {<br \/>\n\t\tfinal BodyDef boxBodyDef = new BodyDef();<br \/>\n\t\tboxBodyDef.type = pBodyType;<\/p>\n<p>\t\tfinal float[] sceneCenterCoordinates = pShape.getSceneCenterCoordinates();<br \/>\n\t\tboxBodyDef.position.x = sceneCenterCoordinates[Constants.VERTEX_INDEX_X] \/ PIXEL_TO_METER_RATIO_DEFAULT;<br \/>\n\t\tboxBodyDef.position.y = sceneCenterCoordinates[Constants.VERTEX_INDEX_Y] \/ PIXEL_TO_METER_RATIO_DEFAULT;<\/p>\n<p>\t\tfinal Body boxBody = pPhysicsWorld.createBody(boxBodyDef);<\/p>\n<p>        for(Vector2[]  v : vertices_list){<br \/>\n    \t\tfinal PolygonShape boxPoly = new PolygonShape();<br \/>\n    \t\tboxPoly.set(v);<br \/>\n    \t\tpFixtureDef.shape = boxPoly;<br \/>\n    \t\tboxBody.createFixture(pFixtureDef);<br \/>\n    \t\tboxPoly.dispose();<br \/>\n        }<\/p>\n<p>\t\treturn boxBody;<br \/>\n\t}<br \/>\n[\/java]<\/p>\n<p>\u3053\u306e\u30af\u30e9\u30b9\u30e1\u30bd\u30c3\u30c9\u3092PhysicsFactory\u306b\u8ffd\u52a0\u3057\u3001\u5b9a\u7fa9\u30af\u30e9\u30b9\u3067\u3082\u4f5c\u3063\u3066\u3001\u30b9\u30d7\u30e9\u30a4\u30c8\u3054\u3068\u306eArrayList\u3092\u5410\u304d\u51fa\u3057\u3066\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u6295\u3052\u3066\u3084\u308c\u3070\u3001\u4f7f\u3044\u3084\u3059\u304f\u306a\u308b\u3093\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(2)\u8907\u6570\u306eVector2[]\u914d\u5217\u304b\u3089Body.\u3092\u4f5c\u308aSprite\u3068\u95a2\u9023\u4ed8\u3051\u308b(\u8907\u96d1\u306a\u5f62\u614b\u306eBody) \u307e\u305a\u3001\u3069\u3046\u3084\u3063\u3066\u8907\u6570\u306eVector2[]\u3092Body\u306b\u6e21\u3059\u306e\u304b\u304c\u3001\u610f\u5916\u306b\u60c5\u5831\u304c\u306a\u3044\u3002\u521d\u3081\u306fBody\u3092joint\u3067\u3064\u306a\u3054 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"","_original_post":"","footnotes":""},"categories":[13,5,20,6],"tags":[],"class_list":["post-834","post","type-post","status-publish","format-standard","hentry","category-andengine","category-android","category-box2d","category-6","ja"],"_links":{"self":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=834"}],"version-history":[{"count":13,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions"}],"predecessor-version":[{"id":1426,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions\/1426"}],"wp:attachment":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}