我正在try 使用Phaser3.目前try 了3.70和3.80测试版,但没有结果. 如果我try 使用someSprite.preFX.addGLow(),它在没有zoom 时工作, 如果我使用zoom 的精灵完全消失.
配置不起作用:
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/phaser/dist/phaser.min.js"></script>
<script>
class BrokenScene extends Phaser.Scene
{
GAME_WIDTH = 640;
GAME_HEIGHT = 960;
sizer;
player;
player2;
platforms;
constructor () {
super('GameScene');
}
preload() {
this.load.spritesheet('dude', 'https://labs.phaser.io/assets/sprites/dude.png', { frameWidth: 32, frameHeight: 48 });
this.load.image('ground', 'https://labs.phaser.io/assets/sprites/platform.png');
}
create () {
const width = this.scale.gameSize.width;
const height = this.scale.gameSize.height;
this.parent = new Phaser.Structs.Size(width, height);
this.sizer = new Phaser.Structs.Size(this.GAME_WIDTH, this.GAME_HEIGHT, Phaser.Structs.Size.FIT, this.parent);
this.parent.setSize(width, height);
this.sizer.setSize(width, height);
this.updateCamera();
this.scale.on('resize', this.resize, this);
this.physics.world.setBounds(0, 0, this.GAME_WIDTH, this.GAME_HEIGHT);
// The platforms group contains the ground and the 2 ledges we can jump on
this.platforms = this.physics.add.staticGroup();
this.platforms.setDepth(10);
// Here we create the ground.
// Scale it to fit the width of the game (the original sprite is 400x32 in size)
this.platforms.create(320, 944, 'ground').setDisplaySize(640, 32).setDepth(10).refreshBody();
// -----------------------[ The glow section ]----------------------------- //
// This one fails... with preFX
this.player = this.physics.add.sprite(100, 800, 'dude');
this.player.preFX.setPadding(32);
const fx = this.player.preFX.addGlow();
// This one works with postFX
this.player2 = this.physics.add.sprite(250, 800, 'dude');
this.player2.postFX.setPadding(32);
const fx2 = this.player2.postFX.addGlow();
// For PreFX Glow the quality and distance are set in the Game Configuration
this.tweens.add({
targets: [fx, fx2],
outerStrength: 10,
yoyo: true,
loop: -1,
ease: 'sine.inout'
});
// -----------------------[ end glow section ]----------------------------- //
this.player.setBounce(0.1);
this.player.setCollideWorldBounds(true);
this.player.setDepth(1);
this.physics.add.collider(this.player, this.platforms);
this.physics.add.collider(this.player2, this.platforms);
}
// Resize related functions
resize (gameSize) {
const width = gameSize.width;
const height = gameSize.height;
this.parent.setSize(width, height);
this.sizer.setSize(width, height);
this.updateCamera();
}
updateCamera () {
const camera = this.cameras.main;
const x = Math.ceil((this.parent.width - this.sizer.width) * 0.5);
const y = 0;
const scaleX = this.sizer.width / this.GAME_WIDTH;
const scaleY = this.sizer.height / this.GAME_HEIGHT;
camera.setViewport(x, y, this.sizer.width, this.sizer.height);
camera.setZoom(Math.max(scaleX, scaleY));
camera.centerOn(this.GAME_WIDTH / 2, this.GAME_HEIGHT / 2);
}
getZoom () {
return this.cameras.main.zoom;
}
update () {}
}
const config = {
type: Phaser.AUTO,
backgroundColor: '#000000',
scale: {
mode: Phaser.Scale.RESIZE,
width: 640,
height: 960,
min: {
width: 320,
height: 480
},
max: {
width: 1400,
height: 1200
}
},
scene: [ BrokenScene ],
fx: {
glow: {
distance: 32,
quality: 0.1
}
},
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
}
};
const game = new Phaser.Game(config);
</script>
</body>
</html>
有什么建议吗?出什么问题了?如果我使用postFX,它会渲染,但我看到的Phaser示例(没有zoom )建议使用preFX.