Phaser Matter Collision Plugin 碰撞插件 -- iFiero技术分享

本文介绍了Phaser游戏中使用Matter物理引擎进行复杂碰撞处理的需求,并推荐了一个碰撞插件,该插件简化了识别和处理相撞物体的过程。通过引入这个插件,开发者可以更方便地进行游戏开发。欲了解更多游戏教学资源,可访问www.iFIERO.com。
摘要由CSDN通过智能技术生成

collision-simple-demo

Phaser 自带的Arcade虽然易用,但复杂的物理碰撞明显就不够用了,于是Matter等物理引擎还是不得不学的,以下是Matter物理体碰撞的一个插件,它省去了我们判别两个物理体相撞后哪个是gameObjectA和gameObjectB,实在是好用又省心,特推荐如下:

引入插件:

const config = {
  // ...
  physics: {
    default: "matter"
  },
  // Install the scene plugin
  plugins: {
    scene: [
      {
        plugin: PhaserMatterCollisionPlugin, // The plugin class
        key: "matterCollision", // Where to store in Scene.Systems, e.g. scene.sys.matterCollision
        mapping: "matterCollision" // Where to store in the Scene, e.g. scene.matterCollision
      }
    ]
  }
};
 
const game = new Phaser.Game(config);

识别二个相撞体

const player = this.matter.add.sprite(0, 0, "player");
const trapDoor =
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值