cocos creator box2d

title Map use box2d

var sfloors = this.tiledMap.getObjectGroup(‘Special_Floor’).getObjects(); //Get the object layer here

< span class="hljs-comment">for (let i = 0, l = sfloors. length; i

{

  let sfloorsgNode = sfloors[ i];

  let compoent = this.floor_physics.addComponent(cc.PhysicsPolygonCollider);< /span>

  let poitlist = sfloorsgNode.getProperties().points //One is here getProperties. I haven’t found the properties of this points for a long time. The result is not on the shNode, and this method is also hidden deep in the document Not at all???< /span>

  compoent.points = [];

  for (var index = 0; index

  {

     poitlist[index].y = -poitlist[index].y;//Flip the collision body compoent.points.push(cc.p(poitlist[index]));

  }

  compoent.offset = new cc.p(sfloorsgNode.sgNode.x, sfloorsgNode.sgNode. y);

}

I wrote a plug-in temporarily,
Operation steps:
1. Set the tiledMap node, select the map file, and edit it. The layer node under the figure
2. Select the layer node and drag the LayerCollider.js file to the node.
3. Generate several static rigid body nodes under the layer node.

Question:
1. It turns out that each tile generates a rigid body, and the result will be more (if you have special needs, it’s okay, similar to the brick of Angry Birds), so I rewrite it, But my algorithm was too lazy to think too much, so I created a rigid body block connected horizontally, reducing a lot of rigid bodies. Of course, if you have the ability, you can also rewrite it as a polygonal rigid body collider, and then calculate the connected area to generate a rigid body. I just used boxCollider
2. It may be generated repeatedly, so I don’t think about how to do it for the time being. Just delete it from the node.
3. Originally wanted to be a standard plug-in, but the interface and operation are not documented, similar to ui-node. And if you operate the node in the editor in reverse, you don’t understand it, so follow the wording similar to hsl_shader, because the documentation is relatively lacking now, and it is not very good.
4. The direction is not considered
5. The diagonal line formed by the image reason is not considered. I am here temporarily with big squares. Anyway, it was generated during the design stage, so change it yourself.
6. Consider that different effects in the map are placed in different layers, so they are generated on the layer, and different generation strategies for different layers can also be considered. I don’t know how to make an interface, let’s talk about it.

LayerCollider.js
/**
* create by shishi11 20170524
*@param{[type]}) {let tlayer [description]
* @return {[type]} [description]*/var LayerCollider = cc.Class({extends: cc.Component,editor: {requireComponent: cc.TMXLayer,executeInEditMode: true },onEnable: function() {let tlayer = this.node.getComponent(cc.TiledLayer);cc.log(tlayer.getLayerSize());cc.log(tlayer.getMapTileSize().width + ‘,’+ tlayer .getMapTileSize().height);cc.log(tlayer.getTiles().length);let tileSize = tlayer.getMapTileSize();let layerSize = tlayer.getLayerSize();let tiles = tlayer.getTiles();for ( let i = 0; i = tiles .length) break;} else {break;}}}}}},});

wrote a plugin temporarily ,
Operation steps:
1. Set the tiledMap node, select the map file, and edit the layer node under the map
2. Select the layer node, and drag the LayerCollider.js file to the node.
3. Generate several static rigid body nodes under the layer node.

Question:
1. It turns out that each tile generates a rigid body, and the result will be more (if you have special needs, it’s okay, similar to the brick of Angry Birds), so I rewrite it, But my algorithm was too lazy to think too much, so I created a rigid body block connected horizontally, reducing a lot of rigid bodies. Of course, if you have the ability, you can also rewrite it as a polygonal rigid body collider, and then calculate the connected area to generate a rigid body. I just used boxCollider
2. It may be generated repeatedly, so I don’t think about how to do it for the time being. Just delete it from the node.
3. Originally wanted to be a standard plug-in, but the interface and operation are not documented, similar to ui-node. And if you operate the node in the editor in reverse, you don’t understand it, so follow the wording similar to hsl_shader, because the documentation is relatively lacking now, and it is not very good.
4. The direction is not considered
5. The diagonal line formed by the image reason is not considered. I am here temporarily with big squares. Anyway, it was generated during the design stage, so change it yourself.
6. Consider that different effects in the map are placed in different layers, so they are generated on the layer, and different generation strategies for different layers can also be considered. I don’t know how to make an interface, let’s talk about it.

LayerCollider.js
/**
* create by shishi11 20170524
*@param{[type]}) {let tlayer [description]
* @return {[type]} [description]*/var LayerCollider = cc.Class({extends: cc.Component,editor: {requireComponent: cc.TMXLayer,executeInEditMode: true },onEnable: function() {let tlayer = this.node.getComponent(cc.TiledLayer);cc.log(tlayer.getLayerSize());cc.log(tlayer.getMapTileSize().width + ‘,’+ tlayer .getMapTileSize().height);cc.log(tlayer.getTiles().length);let tileSize = tlayer.getMapTileSize();let layerSize = tlayer.getLayerSize();let tiles = tlayer.getTiles();for ( let i = 0; i = tiles .length) break;} else {break;}}}}},});

Leave a Comment

Your email address will not be published.