背景虚化或者镜头虚化效果
this.add.image(400,300,'bg').setScale(1.0).setScrollFactor(0,0)
const grass=this.add.layer()
// 创建一个层
const trees=['Spruce-1', 'Spruce-2', 'Spruce-3', 'Spruce-5', 'Spruce-6', 'Flower_2']
for (let i = 0; i < 128; i++){
let x = Phaser.Math.Between(0, 800);
let y = Phaser.Math.Between(100, 600 * 4);
// 这里的坐标也应该在一个固定的范围里面去随机,而且是不重复的
let frame = Phaser.Utils.Array.GetRandom(trees);
// 从数组里面随机拿里面的额一个值
let tree = this.add.image(x, y, 'glade', frame);
tree.setDepth(y);
tree.setOrigin(0.5, 1);
grass.add(tree);
}
// const camera=this.cameras.main
// camera.postFX.addVignette(0.5,0.5,0.6)
// 对镜头使用虚化
对单个元素使用虚化+切换虚化效果
const play=this.add.image(400,520,'playButton')
// const fx=play.postFX.addGlow(0xfffffb,0,0,false,0.1,32)
const fx=play.postFX.addGlow(0xfffffb,0,0,true,0.1,32)
this.tweens.add({
targets:fx,
outerStrength:4,
yoyo:true,
loop:-1,
ease:"sine.inout"
})
外发光 addGlow
const bomb1 = this.add.sprite(200, 300, 'bomb');
const bomb2 = this.add.sprite(600, 300, 'bomb');
const fx1 = bomb1.postFX.addGlow(0xffffff, 0, 0, false, 0.1, 32);
const fx2 = bomb2.postFX.addGlow(0xff0000, 8, 8, true, 0.1, 24);
this.tweens.add({
targets: fx1,
outerStrength: 8,
yoyo: true,
loop: -1,
ease: 'sine.inout'
});