let container = new PIXI.Container() //创建容器存放障碍物
for (var i = 0; i < 10; i++) {
// 创建障碍物
let obstacle = new PIXI.Sprite(PIXI.Texture.from('https://img.alicdn.com/imgextra/i2/39767794/O1CN01lzcmmi27RhbhlMlhW_!!39767794.png'))
let flags = true //控制碰撞,碰撞后避免持续触发碰撞函数
obstacle.x = Math.random() * application.screen.width
obstacle.y = Math.random() * application.screen.height
container.addChild(obstacle)
application.stage.addChild(container)
application.ticker.add(() => {
obstacle.y += 2
if (this.hitTestRectangle(obstacle, firfox)) {
if (flags) {
container.removeChild(obstacle) //碰撞后删除元素
flags = false
}
}
})
}
检测碰撞函数
// 碰撞检测
hitTestRectangle(r1, r2) {
//Define t