昨天《Phaser框架的必要知识》结尾写到背景移动,实际上phaser未必提供人物和物理边缘碰撞的回调函数。
(或者这个回调函数里写背景变换,这样设计不是很好,因为需要准备的图片比较多)
镜头移动
实际上phaser3提供了镜头的物理实体,先看代码:
this.cameras.main.setBounds(0, 0, 1920 * 2, 1080 * 2);
this.physics.world.setBounds(0, 0, 1920 * 2, 1080 * 2);
player.setCollideWorldBounds(true);
this.cameras.main.startFollow(player, true, 0.05, 0.05);
“this.cameras.main.setBounds(0, 0, 1920 * 2, 1080 * 2);”这句就是设置镜头的大小,
“player.setCollideWorldBounds(true);”是设置主角可以与世界边缘碰撞,
“this.cameras.main.startFollow(player, true, 0.05, 0.05);”是设置镜头跟随人物,true先不管它,0.05是代表跟随的快慢,这个值越大,说明镜头跟随人物越快。
![](https://img.haomeiwen.com/i11599718/a3cab855f8fe8173.png)
网友评论